April 11th, 2011, 09:37 AM
Join Date: Feb 2011
Time spent in forums: 1 h 27 m 12 sec
Reputation Power: 0
Need help adding an option
I am working on this program that does a variety of things.
It checks for the existence of a file,
It checks to see if a user is logged on,
Then I ca choose to have the results mailed to me or to be displayed on screen.
Now I am trying to add an option of -n to invert monitoring to see when the user logs OFF.
Ive tried everything. Can someone just give me a place I should start at? Im lost.
while getopts mnf:t: option
f) if [ -f "$OPTARG" ]
echo "File exits"
echo "File doesnt exist"
\?) echo "Usage: mon [-m] [-t n] [-f] user"
echo " -m means to be informed by mail"
echo " -t means check every n secs"
echo " -f means check for existence fo a file"
if [ "$OPTIND" -gt "$#" ]
echo "Missing user name!"
shiftcount=$((OPTIND - 1))
until who | grep "^$user " > /dev/null
term=$(who | grep $user | cut -d' ' -f3)
if [ "$mailopt" = FALSE ]
echo "$user has logged on $user has logged on to terminal $term"
runner=$(who am i | cut -c1-7)
echo "$user has logged on to terminal $term" | mail $runner