UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 11th, 2011, 08:37 AM
losingit losingit is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2011
Posts: 5 losingit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 27 m 12 sec
Reputation Power: 0
Need help adding an option

Hey all.
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.

Code:
mailopt=FALSE
interval=5


while getopts mnf:t: option
do
case "$option"
in
m) mailopt=TRUE;;
t) interval=$OPTARG;;
f) if [ -f "$OPTARG" ]
then
echo "File exits"
else
echo "File doesnt exist"
fi
exit 1;;
\?) 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"
    exit 1;;
esac
done

if [ "$OPTIND" -gt "$#" ]
then
echo "Missing user name!"
exit 2
fi

shiftcount=$((OPTIND - 1))
shift $shiftcount
user=$1

until who | grep "^$user " > /dev/null
do
sleep $interval
done

term=$(who | grep $user | cut -d' ' -f3)

if [ "$mailopt" = FALSE ]
then
echo "$user has logged on $user has logged on to terminal $term"
else
runner=$(who am i | cut -c1-7)
echo "$user has logged on to terminal $term" | mail $runner
fi

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Need help adding an option

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap