Monday, February 26, 2007
Checking after every 5 seconds whether a user is log into the system or not
Again, sort of academic assignment question, but for a BASH learner, I feel will be useful.
#!/bin/sh
USER="build"
total=0
echo "Checking whether \"$USER\" is logged in or not"
echo "Starting at : `date`"
while :
do
who | grep $USER > /dev/null
[ $? = 0 ] && echo "Logged in" && exit
sleep 5
total=`expr $total + 5`
echo "User \"$USER\" Not yet logged in($total secs passed)"
done
$ ./checklo.sh
Checking whether "build" is logged in or not
Starting at : Fri Dec 14 09:48:17 IST 2007
User "build" Not yet logged in(5 secs passed)
User "build" Not yet logged in(10 secs passed)
User "build" Not yet logged in(15 secs passed)
Logged in
The same can also be checked using until loop
$ until who | grep build; do echo "Not yet" ;sleep 5; done; echo "Logged In"
Subscribe to:
Post Comments (Atom)
© Jadu Saikia www.UNIXCL.com
No comments:
Post a Comment