Hi,
I need a little bit of help with debugging of this script. The purpose of this script is to check if a particular user has logged in. If logged out, then I would like to send an email containing the output of a log to a set of email ids.
Code:
#! /bin/sh
echo "The current users are:"
who | awk '{print $1}' | sort > temp1
cp temp1 temp2
more temp1
while true
do
who | awk '{print $1}' | sort > temp2
cmp -s temp1 temp2
case "$?" in
0)
echo "No user has logged in/out in the last 5 seconds."
;;
1)
user='gayathri'
file=`grep $user temp1 temp2 | cut -c 1-5`
file=`grep $user temp1 temp2 | cut -c 1-5`
if [ $file = "temp1" ]
echo "User "$user" has logged out."
if [ $file = "temp2" ]
echo "User "$user" has logged in."
;;
esac
rm temp1
mv temp2 temp1
done