command timeout in ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting command timeout in ksh
# 8  
Old 09-09-2012
I was able to modify the solution in another forum to match my requirement.
I tested and this is perfect for me. I appreciate all your help.

Code:
#!/bin/ksh 
 
WAITTIME=5 
 
# run the idql command in the background, discarding any output 
idql -n $REPOSITORY_NAME -Udmadmin -P"" -R"$DM_SCRIPTS/test.api" >/dev/null 2>&1 & 
IDQL_PID=$! 
 
# set up a timeout that will kill the idql command when  
# $WAITTIME seconds has passed, unless it has completed before that. 
(sleep $WAITTIME; kill $IDQL_PID 2>/dev/null) & 
TIMEOUT_PID=$! 
 
# wait for the idql command to either complete or get killed; read its return status 
wait $IDQL_PID 
RESULT=$? 
 
# if the timeout is still running, stop it (ignore any errors) 
kill $TIMEOUT_PID 2>/dev/null 
 
# read the return status of the timeout process (we don't need it  
# but running the wait function prevents it from remaining as a  
# zombie process) 
wait $TIMEOUT_PID 
 
if [ $RESULT -eq 1 ];then 
    echo "something is wrong with $REPOSITORY_NAME, It seems to be down. Result - $RESULT" 
elif [ $RESULT -eq 143 ];then 
    echo "Attention!!! ***$REPOSITORY_NAME seems to be HUNG*** Result - $RESULT" 
else 
    echo "$REPOSITORY_NAME seems to be OK. Result - $RESULT" 
fi

These 2 Users Gave Thanks to vishnudev1 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Timeout to abolish ssh connection command it takes too long

Hi, I am running a ssh connection test in a script, how can I add a timeout to abolish the process if it takes too long? ssh -i ~/.ssh/ssl_key useraccount@computer1 Thank you. - j (1 Reply)
Discussion started by: hce
1 Replies

2. Shell Programming and Scripting

Using awk command in ksh

I am trying to use awk command withing ksh. ksh "echo \"my name\" | awk '{print $2}'" I am getting out as : my name Expected output: name When I use echo "my name" | awk '{print $2}' I am getting the correct output: name I am not sure what mistake I am doing when using awk... (1 Reply)
Discussion started by: Bala_db2
1 Replies

3. Shell Programming and Scripting

Mailx command timeout Issue

Hi All, I have a situation where we need to send out mails from our Unix server to different mailing ids inside our scripts.The mails are working fine.But we have occasional issues where we are getting time out errors from the SMTP server while sending out mails. Command that we are using... (3 Replies)
Discussion started by: DevotedPupil
3 Replies

4. Shell Programming and Scripting

Command timeout from inside script.

Hi, I've written a very robust script to get an external IP address from 'behind' a router. It uses many web pages randomly choosing which one/ones to use at run time. The "fetch the web page containing the IP address" is handled by either wget or curl both of which have their 'max time for the... (6 Replies)
Discussion started by: gencon
6 Replies

5. Shell Programming and Scripting

php shell_exec, exec command timeout

HI, Does anybody know if its possible to execute a command through exec, shell exec, system and if the program doesn't terminate in N seconds returns control to PHP ? reg, research3 ---------- Post updated 10-16-09 at 12:20 AM ---------- Previous update was 10-15-09 at 11:03 PM... (1 Reply)
Discussion started by: research3
1 Replies

6. Shell Programming and Scripting

KSH script SQL timeout issue

Hi all, I have a KSH script which is kicking off an sql scripts as follows: /usr/local/installs/instantclient_10_2/sqlplus -s username/password @$sql_path/sql_query.sql > $tmp_path/sql_query_results The problem I have is that sometimes the 10g Oracle Database spits out an error saying... (4 Replies)
Discussion started by: Donkey25
4 Replies

7. Shell Programming and Scripting

awk/sed Command : Parse parameter file / send the lines to the ksh export command

Sorry for the duplicate thread this one is similar to the one in https://www.unix.com/shell-programming-scripting/88132-awk-sed-script-read-values-parameter-files.html#post302255121 Since there were no responses on the parent thread since it got resolved partially i thought to open the new... (4 Replies)
Discussion started by: rajan_san
4 Replies

8. Shell Programming and Scripting

Can we timeout cd command

Hi All, I want to know whether we can timeout the cd command in unix. If we can how is it implemented? Suppose cd command hangs can we timeout the command. Please help (9 Replies)
Discussion started by: dipashre
9 Replies

9. Shell Programming and Scripting

How to timeout the "read" command

I have a script that at some point will ask the interactive user a question: #!/bin/ksh echo "What is your access code?" read ans ... Sometimes this script is run by other scripts and there are no interactive users. The script then hangs on the "read" command, waiting for a user response... (5 Replies)
Discussion started by: rm-r
5 Replies

10. Shell Programming and Scripting

ksh read timeout

any idea on how to timeout the read statement for ksh? for bash u can use read -t option -t timeout Cause read to time out and return failure if a complete line of input is not read within timeout seconds. This option has ... (2 Replies)
Discussion started by: ashterix
2 Replies
Login or Register to Ask a Question