I have a script that displays whether a user is online or not and if they are it displays how long and if not it displays the last time they were logged on.
Now I am trying to make it so if a user is not recognized it simply says the user has never been online.
this is what I have so far
if [ $# -lt 1 ]
then
echo "You must supply a username."
exit 1
fi
if
who|grep -qw ^$1>/dev/null 2>&1
then
who | grep $1 | awk '{print $1 " has been online since " $3 " "$4}'
else
last | grep $1 | awk '{print $1 "is not online and last logged in " $5 " " $6 " " $9 $
fi
My question is in the last if else statement, can I just add an elseif and basically search 'last' for the user and if it returns nothing display an error message? Something like this (this doesn't work just what I had in mind)
$
elif [ $? -eq 1]
then
echo "$1 is not online and has never logged in."
fi
Any help is appreciated thank you