Welcome to the Linux Foundation Forum!

I am trying to create a isloggedin script

kingalbright
kingalbright Posts: 1
edited April 19 in Command Line/Scripting

Hello, I am pretty new to scripting and am trying to create a iloggedin.sh script. I am having trouble making it work. Any help is well appreciated.

user=$1

echo $user

userexists=grep ^${user}: /etc/passwd
if [ -z "$userexists" ]; then
echo "$user does not exist"
else

   echo "$user does exist"
   isloggedon=`who | cut -d" " -f1 | grep ^${user}$`
   if [ "$isloggedon" ]; then
        echo "$user is currently logged on."
   else



   echo $lastlogon | awk '{ print $5" "$6" "$7" "$8" "$9"}'
   lastlogon=`lastlog -u $user | tail -1`
   echo -n "$user last logged on at "


   never=`echo $lastlogon | grep Never`
   if [ -z "$never"];then
           echo "$user never logged in."
   else

   fi

fi
exit

Categories

Upcoming Training