Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorry new bug in menu timeout help....

Status
Not open for further replies.

lpblauen

Technical User
Dec 2, 2004
193
US
I have been running the new helpmenu with the timeout set as per PHV. It works great but. Managment doesn't like the sleeps in ps -ef. The problem is I get 900 sleeps in the process list to make it timeout in 15 minutes.
Is there another way to make the menu timeout without putting processes in the ps -ef over and over again. The sleep's do go away after the process is ended.

helpdesk 11068 1 0 08:28:58 pts/10 0:00 sleep 900
helpdesk 26724 1 0 08:29:21 pts/10 0:00 sleep 900
helpdesk 39534 1 0 08:29:21 pts/10 0:00 sleep 900
helpdesk 56764 1 0 08:22:04 pts/10 0:00 sleep 900
helpdesk 61700 1 0 08:29:20 pts/10 0:00 sleep 900
helpdesk 63294 1 0 08:29:20 pts/10 0:00 sleep 900
helpdesk 72082 124102 0 08:29:21 pts/10 0:00 sleep 900
helpdesk 72360 1 0 08:29:20 pts/10 0:00 sleep 900
helpdesk 76842 1 0 08:29:21 pts/10 0:00 sleep 900
helpdesk 89650 1 0 08:29:20 pts/10 0:00 sleep 900
helpdesk 90338 1 0 08:29:21 pts/10 0:00 sleep 900
helpdesk 96828 1 0 08:29:19 pts/10 0:00 sleep 900
blauenl 109246 44548 0 08:29:23 pts/11 0:00 grep sleep
helpdesk 116730 1 0 08:29:20 pts/10 0:00 sleep 900

This seems to happen everytime you hit enter and the menu redraws. The pid changes and the old one just sits there till the timeout happens. This adds up to many sleeps.

Here is the menu program

# 900 sec is 15 minutes
# 1800 sec is 30 minutes
# Purpase: Help Desk menu
# Name: helpmenu
clear
TIMEOUT=120
while
trap 'print "Problem with Help Desk menu"; exec kill -9 $PPID' HUP INT QUIT STOP

print " Helpdesk Menu Options"
print " 1) Add users"
print " 2) Change password"
print " 3) Check printer status"
print " 4) Delete printer jobs "
print " 5) Reset printer "
print " 6) Show users on the system"
print " 7) Show an account"
print " 8) Clean up IP address"
print " 9) Logout "
print
(sleep $TIMEOUT; kill -15 $$ >/dev/null 2>&1) &

do read SEL?" Option: "; RC=$?
kill -9 $! >/dev/null 2>&1
case "$SEL" in
1)command ;;
etc..........................
esac
done

 
I figured out a way to fix this I just added the following to the menu and it kills leftover sleeps.

ps -ef | grep sleep | awk '{print $2,$3}' >1
cat 1 | while read A B
do
if [ "$B" = "1" ]; then
kill -9 $A 2>&1
else
print " "
fi
done

 
I'd leave out the temp file named "1":

ps -ef | grep sleep | awk '{print $2,$3}' | while read A B
do
if [ "$B" = "1" ]; then
kill -9 $A 2>&1
else
print " "
fi
done


HTH,

p5wizard
 
You could use this wrapper to timeout any command


Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top