Sponsored Content
Top Forums Shell Programming and Scripting How to skip command if it is hanging while waiting for response Post 302499574 by Chubler_XL on Thursday 24th of February 2011 06:19:50 PM
Old 02-24-2011
How about tis (if your sleep dosn't support decimal values ie only whole integers you will need to sleep 1 instead and reduce your wait count to 2).
If you don't have the /proc filesystem you will need to run ps -p $WPID 2> /dev/null and test the exit status

Code:
#!/bin/bash
whois 1.2.3.4 > /tmp/wi$$.out &
WPID=$!
while [[ -d /proc/$WPID ]] && [[ $((++wait)) -lt 8 ]]
do
    sleep 0.25
done
if [[ -d /proc/$WPID ]]
then
    WHOIS="<unknown>"
    echo "whois taking too long - killing"
    kill $WPID
else
    WHOIS=$(cat /tmp/wi$$.out)
fi
rm /tmp/wi$$.out

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

read-waiting for user response

Would there be any reason for why a 'read ans' would not wait for a user's response (i.e user has to hit a key to continue)? I know for sure that it is doing everything else in that part of my 'if' statement but it doesn't wait for me to hit a key before continuing. The strange thing is that... (4 Replies)
Discussion started by: giannicello
4 Replies

2. UNIX for Dummies Questions & Answers

ps command is hanging

Hi All, I am unable to figure out why my ps command is haning. Is some one else is running a process which is hanged. But in that case also if i do ps it should show only the processes running by me only. Thanks & Regards Gauri Agrawal (2 Replies)
Discussion started by: gauri
2 Replies

3. UNIX and Linux Applications

waiting for ssh response for seconds

Hi All, I have to make an alert that'll wait for ssh response from the server for certain seconds, if no response is there in between it'll raise an alarm. Havn't found any option for this yet, pls. help if anyone knows abt this. Any suggestion is welcome. :) Best Regards, VG (3 Replies)
Discussion started by: vguleria
3 Replies

4. UNIX for Dummies Questions & Answers

Sz command hanging and outputting ZNAK’s

Currently I am using the following sz and rz commands to run file transfer using ZMODEM within a perl script. sz -b -m1 -M2 -k -e -r -u -t10 rz -b -m 1 -M 120 -y Is there any flag setting that will allow me to terminate when a retry 0 error is outputted as this is constantly filling up my... (0 Replies)
Discussion started by: M1keSt4r
0 Replies

5. Shell Programming and Scripting

read command not waiting

Dear All, read command not waiting for my input, please suggest. code: while read line do echo "$line " | grep -i .par$ if ; then cd ../par echo " Do you want to proceed" read else cd ../sql read fi done <inp.txt Its not asking me any input? (2 Replies)
Discussion started by: mahendra singh
2 Replies

6. Solaris

df command hanging

Hi Folks, When i execute the command df -kh in my system the o/p hangs.. The command runs fine but takes a lot of time before coming back to the # prompt. Can anyone please suggest the possible cause and solution?. (10 Replies)
Discussion started by: vivek.goel.piet
10 Replies

7. UNIX for Dummies Questions & Answers

passing input into a cmd line that's waiting for a response

Hi, I am writing a little script to update a parameters on JMQ. however the JMQ requires a "y" confirmation to be input as part of the cmd I am running. However I want run this script to offline with no input from a user. it works if a I create a file with with just y in it and pass that in... (3 Replies)
Discussion started by: shropshirehobbi
3 Replies

8. Shell Programming and Scripting

Can I skip files when running rm command

Platform: Oracle Enterprise Linux 6.2 I have several files like below. I want to remove all files except one file For example , I want to remove all the files below except dasd_91197.trc $ ls -alrt *.trc -rw-r----- 1 ecmdev wms 8438784 May 7 21:30 dasd_91177.trc -rw-r----- 1 ecmdev wms ... (3 Replies)
Discussion started by: John K
3 Replies

9. Shell Programming and Scripting

sed Command to skip

Friends, I have 1000 line like below #formate Test.server.e01=http://111.22.33.23/ #test_server_west Test.server.w01=http://112.123.123.22/ Test.server.w02=http://113.143.123.22/ Test.server.w03=http://112.183.123.22/ #test_server_east Test.server.e01=http://115.123.123.22/... (6 Replies)
Discussion started by: jothi basu
6 Replies

10. Shell Programming and Scripting

awk hanging from running command

awk -v youth=1599 -v d="$(/bin/ps -ef)" 'd ~/ 1599 / && d !~/ awk / && (($2 == youth) || ($3 == youth)) {print $2" "$3}' i feel like i'm very close here. what am i doing wrong? (1 Reply)
Discussion started by: SkySmart
1 Replies
exit(1)                                                            User Commands                                                           exit(1)

NAME
exit, return, goto - shell built-in functions to enable the execution of the shell to advance beyond its sequence of steps SYNOPSIS
sh exit [n] return [n] csh exit [ ( expr )] goto label ksh *exit [n] *return [n] DESCRIPTION
sh exit will cause the calling shell or shell script to exit with the exit status specified by n. If n is omitted the exit status is that of the last command executed (an EOF will also cause the shell to exit.) return causes a function to exit with the return value specified by n. If n is omitted, the return status is that of the last command exe- cuted. csh exit will cause the calling shell or shell script to exit, either with the value of the status variable or with the value specified by the expression expr. The goto built-in uses a specified label as a search string amongst commands. The shell rewinds its input as much as possible and searches for a line of the form label: possibly preceded by space or tab characters. Execution continues after the indicated line. It is an error to jump to a label that occurs between a while or for built-in command and its corresponding end. ksh exit will cause the calling shell or shell script to exit with the exit status specified by n. The value will be the least significant 8 bits of the specified status. If n is omitted then the exit status is that of the last command executed. When exit occurs when executing a trap, the last command refers to the command that executed before the trap was invoked. An end-of-file will also cause the shell to exit except for a shell which has the ignoreeof option (See set below) turned on. return causes a shell function or '.' script to return to the invoking script with the return status specified by n. The value will be the least significant 8 bits of the specified status. If n is omitted then the return status is that of the last command executed. If return is invoked while not in a function or a '.' script, then it is the same as an exit. On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a vari- able assignment. This means that tilde substitution is performed after the = sign and word splitting and file name generation are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
break(1), csh(1), ksh(1), sh(1), attributes(5) SunOS 5.10 15 Apr 1994 exit(1)
All times are GMT -4. The time now is 05:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy