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!

While loop isnt working

Status
Not open for further replies.

nogs

Technical User
Aug 3, 2001
89
GB
Script below isnt working correctly, had wanted it to logout from the menu if no keystrokes for 30 minutes - can any one see where ive gone worong?
Thanks for your help in advance

#!/bin/sh
ok=0
while [ $ok -eq 0 ]; do
clear
cat <<__END




MENU
------------------------
Choose an option.

(1).
(2).
(3). Email.
(4).
(5). Lynx.
(6). Admin.
(15). Logout.

`logname` `date '+Terminal LAST USED: %H:%M:%S'`


__END
COUNTER=0
while [ $COUNTER -lt 30 ];
do
sleep 60
COUNTER=`echo &quot;$COUNTER + 1&quot;|bc`
if [ $COUNTER >29 ]
then
echo &quot;you were idle too long&quot;
ok=1
exit
fi
done

read ans
case &quot;$ans&quot; in
1)
echo
;;
2)
echo
;;
3)
echo Email. ; /appl/pine/pine
;;
4)
echo Generic. ; ./gen.sh
;;
15)
exit
;;
 
You are missing a semi-colon after the if statement and before the 'then' operator.

I've stuck it in in bold below....

COUNTER=0
while [ $COUNTER -lt 30 ];
do
sleep 60
COUNTER=`echo &quot;$COUNTER + 1&quot;|bc`
if [ $COUNTER >29 ] ;
then
echo &quot;you were idle too long&quot;
ok=1
exit
fi
done

Adam F
Solaris System Administrator
 
or forget the loop, uses processor time. do the following instead

use ksh

set TMOUT=3600 in .profile of user

the 3600 is seconds / 3600 = 60 mins

and just use the following menu

#!/bin/ksh

trap '' 0 1 2 3 15

ans=0
until [ $ans = 99 ]
do

clear

echo &quot; \n\n#----------------------------------------------#&quot;
echo &quot; | Operations Menu |&quot;
echo &quot; #------------------------------------------------#&quot;
echo &quot; |&quot;
echo &quot; | 1.) Check System |&quot;
echo &quot; |&quot;
echo &quot; | 2.) Eject tape after a failed |&quot;
echo &quot; |&quot;
echo &quot; |&quot;
echo &quot; |&quot;
echo &quot; | 99.) |&quot;
echo &quot; |&quot;
echo &quot; #------------------------------------------------#&quot;
echo &quot; Please Enter Your Selection ...\b\b\b\c &quot;
read ans

case $ans in

1) check_sys.sh ;;
2) eject_tape.sh ;;
99) exit ;;
*) error.sh ;;

esac
done

Mike --
| Mike Nixon
| Unix Admin
| ----------------------------
 
mrn
The reason for this menu being put in place is so everyone in our Company is using the same menu - this will involve 100s of people I dont have time to edit all the .profiles

Is there anyway i can start the loop and allow this to be broken by a keypress - as I think this is causing my problem.
Thanks
Nogs
 
You don't have to edit all the .profiles just edit /etc/profile put the TIMEOUT and run menu from there.

Mike --
| Mike Nixon
| Unix Admin
| ----------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top