Hello,
I just started with shell and i am doin simple script to check if certain user is logged in. Script takes 3 args. name sleep time and quit value
if there is q for quit then date and user name is printed to file, not to screen.
so far i have got this...
login()
{
while :
do
if [[ `who | grep -c $name` -gt 0 ]]
then
echo "\a user $name is logged in"
echo "User $name has logged in. `date` >> logs.txt"
sleep $freq
else
echo "User $name is not logged in"
sleep $freq
fi
done
}
loginQ()
{
while :
do
if [[ `who | grep -c $userName` -gt 0 ]]
then
echo "User $name has logged in. `date` >> logs.txt"
sleep $freq
else
sleep $freq
fi
done
}
if [ $# -le 3 -a $# -ge 1 ]
then
name=$1
freq=$2
quit=$3
else
echo Invalid number of arguments
fi
if [ -z $frequency ]
then
frequency=60
fi
if [ $quit = q ]
then
loginQ()
else
login()
fi
Could someone help me with that if grep statement,as its not doing the work and is that if statment to check if freq is integer correct ?