Headlines
Loading...
Program in UNIX which checks after every one-minute whether user has logged in or not

Program in UNIX which checks after every one-minute whether user has logged in or not

A friend of yours has promised to log in at a particular time. However, he has not kept the promise. You want to contact him as soon as he logs in. Write a shell script which checks after every one-minute whether your friend has logged in or not. The logname should be supplied to the shell script at command prompt.
echo "Enter User number :"
read un

x=`who | grep $un |wc -l`

if [ $x -ne 0 ]
then
        echo "User $un logged in "
else
        while [ $x -eq 0 ]
        do
                sleep 2
                x=`who|grep $un|wc -l`
                if [ $x -ge 1 ]
                then
                        echo "now user logged in "
                        write $un >hi
                        exit
                fi
        done
fi
*** PLEASE checkout the Best deals from for top sites like Amazon, Flipkart etc ***