Bash Help: users who are not logged into the system to display

A Newbie here,

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 

Joey G,

I put the $ in where you suggested, and it still does not work right. Any other ideas?

Thanks for your help.

Rob

With awk:

awk 'BEGIN{while("who" | getline)w[$1]}
$1 in w {print $1 " is logged in"; next}
{print $1 " is NOT logged in"}
' FS=":" /etc/passwd

Try this command .....

grep -v `who | tr -s " " | cut -d" " -f1` /etc/passwd | awk -F":" '{print $1}'

Thanks everyone for your help!

I appreciate it

Rob