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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

timeout in unix korn shell script 1

Status
Not open for further replies.

RobJordan

MIS
Apr 3, 2001
296
US
I have created a script to startup and shutdown processes which works great.
I would like to create a timeout to wrap around the commands
in the script. The idea is that if one the commands hangs, the timeout
will intervene after specified time and call my paging function to alert
me of a problem. I would like to do this in k shell if possible.

Thanks in advance,

Robert G. Jordan
 
Well, I am disappointed. I received no answers to my
question so I had to answer the question myself.
Here's my solution.

#!/bin/ksh

clear

ps -ef 2>&1 > /tmp/ls.tmp & # launching some process in the background

RUNNING="true"
TIMER="0"

while [ "$RUNNING" = "true" ]
do
JOBS=`jobs`
NUM_JOBS=`echo $JOBS|awk '{print $1}'`

if [ "${#JOBS}" -gt "0" ]
then
echo "$NUM_JOBS Job(s) still running"
else
echo "No jobs running"
RUNNING="false"
fi

sleep 1
TIMER=`expr $TIMER + 1`
echo "TIMER = $TIMER"

if [ "$TIMER" -gt "2" ]
then
echo "Took to much time"
break
fi
done


echo "$TIMER seconds have passed."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top