0% found this document useful (0 votes)
4 views2 pages

Check User Login Status Script

The document provides a shell script to check if a specified user is currently logged in. It includes two methods: one that writes the output of the 'who' command to a file and checks for the username, and another that directly counts occurrences of the username in the output of 'who'. Both methods output whether the user is logged in or not based on the results.

Uploaded by

for11trade
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Check User Login Status Script

The document provides a shell script to check if a specified user is currently logged in. It includes two methods: one that writes the output of the 'who' command to a file and checks for the username, and another that directly counts occurrences of the username in the output of 'who'. Both methods output whether the user is logged in or not based on the results.

Uploaded by

for11trade
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Script No .

Definition:
Write a shell script to check whether the named user is currently logged in or not.
Script:
clear
echo enter the username
read un
who > userfile
a=`grep "$un" userfile`
c=`echo $a | wc -c`
if [ $c -lt 2 ]
then
echo $un Not logged in
else
echo $un is logged in
fi

OR
echo "Eneter the username"
read un
c=`who | grep -c $un`
if [ $c -gt 0 ]
then
echo "User is currently logged in "
else
echo "User is not currently logged in "
fi

You might also like