How to detect the user has logged in a domain or local host in the linux shell script?
2
votes
1
answer
3786
views
In the default, the linux doesn't support the domain. But the user can join a domain by applictions, such as: Likewise, Winbind, and so on.
For my project, my customers are all enterprise members. For the security problem, most customers' linux host will be joined a domain.
Unfortunately, the customer can log in the local host even the linux host has been joined a domain. Such as:
(1) The are two accounts in a linux host:
a domain account: dev.com\john(the domain is developer.com)
a local account: tom
(2) The customer can log in with the domain account(dev.com\john) or local account(tom) freely.
My task is that write a shell script that will be executed when the user log in. In the shell script, I need to check the user log in with a domain account or a local account.
If the user log in with the domain name, I need to get the domain name ; otherwise, I need to get the host name. Then report the domain(or host) name and user name to the remote monitor server.
I have tried the following code:
hostName=$(hostname)
hostFQDN=$(hostname -f)
if [ "$hostName" = "$hostFQDN" ]; then
# The user didn't log in a domain.
hostInfo="$hostName"
else
# The user logged in a domain.
hostInfo=$(hostname -d)
fi
In the above, I check the host FQDN is equal with the host name or not. If yes, I will believe the customer log in with the domain account; else, local account.
Unfortunately, it doesn't work always. The reason is that the host FQDN will not equal with host name always if the linux host is joined a domain, even the customer log in with a local account. Such as:
(1) The linux host is joined the domain "dev.com";
(2) The host fqdn will be "yw-host.dev.com" always("yw-host" is the host name), whether the customer log in with domain account or not.
Anybody can give a solution please? As my customer can join the domain with multiple domain applications(such as: likewise, winbin, and so on), it is better the solution will not depend on a special domain application.
Thanks a lot.
Asked by yw5643
(161 rep)
May 13, 2015, 07:20 AM
Last activity: Jun 5, 2025, 06:00 AM
Last activity: Jun 5, 2025, 06:00 AM