I am working on a script and am having problems with the else part of the script. I can't get the users who are not logged into the system to display on the screen with their username and the text "The user is not logged in". I am sure it is something simple and stupid, but I can't find out what my issue is.
Please help.
Thanks,
Rob
users=`cat /etc/passwd | cut -d: -f1`
for i in $users
do
isloggedin=`who | grep $i | head -1`
if [ -n isloggedin ]
then
echo $isloggedin
else
echo $users
fi
done
In your if statement, you were not referring to isloggedin with the $
users=`cat /etc/passwd | cut -d: -f1`
for i in $users
do
isloggedin=`who | grep $i | head -1`
if [ -n $isloggedin ]
then
echo $isloggedin
else
echo $users
fi
done