Script to Proceed to the Next IP if the current IP hangs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to Proceed to the Next IP if the current IP hangs
# 8  
Old 10-14-2017
Quote:
Originally Posted by bakunin
The problem is: we do not really know what "doesn't work" means. If it is that the quoted line just hangs and doesn't finish: start it in the background and have a wait command at the end collecting all the hanging processes. There are a lot of threads here dealing with exactly this problem.

If you mean by "doesn't work" that the process just comes back unsuccessfully: usually a process has a return code. You can query this return code and re-run the process if it is not zero (0 usually means it was successful and everything else some sort of failure).

Replace the quoted line with something like this:

Code:
MAXRETRIES=<some number>       # define this at the beginning globally

...

(( iCnt = MAXRETRIES ))
while ! unicornscan -i ${iface} -mT ${ip}:a  -r20000 -l ${log_dir}/udir/${ip}-tcp.txt && [ $iCnt -gt 0 ] ; do
     (( iCnt -= 1 ))
done

This will try MAXRETRIES times to execute the code until it is either successful or the number of tries run out.

I hope this helps.

bakunin
Hi,

I was actually thinking of 3 conditions:
1.Move on to the next line if doesn't work or hang
2. Restart until it works and move to the next line
3. Wait for a number of seconds , if it doesn't move to the next line, restart the current line (just in case for whatever reason there is no exit code)

Unfortunately for my case it still doesn't work after applying the code above. It still hangs
Code:
Send exiting main didnt connect, exiting: system error Interrupted system call
Recv exiting main didnt connect, exiting: system error Interrupted system call


Last edited by alvinoo; 10-14-2017 at 09:42 PM..
# 9  
Old 10-15-2017
That doesn't sound like "hanging" (no more activities nor reactions) but more like exiting with an error. It would be very surprising if NO error resp. exit code were given indicating what error occurred.

Definitely more info is necessary here.

Same for your three conditions. What in bakunin's proposal doesn't solve your problem? Please be way more informative!
# 10  
Old 10-15-2017
This is one way on how you trap a too long wait for a command.
1. set up a child process that kills the parent after a pre-set time.
2. run the command
3. clean up child

Code:
#!/bin/bash

# sleep for a while then clobber parent
# 30 is the value for the signal SIGUSR1 on my system
# SIGUSR1 is a signal that the system does not care about at all, you use it locally

naptime() {
    
    sleep 10 # take a nap
    kill -n 30 $PPID  # wake the parent 
}

run_ssh()
{
    trap 'echo "ssh took too long"; return 1'  SIGUSR1  # return an error
    naptime & 
    naptime_pid=$!
    ssh myuser@somewhere.com 'ls myfile.txt'  # you better be sure this command will complete on success in less than 10 seconds
    kill $naptime_pid
    return 0 # no error
}

# -------- main
run_ssh   # will run for 10 seconds max
ssh_rc=$?
[ $ssh_rc -q 0 ] && echo "things went fine"  || echo "oops ssh timout error"

Also, I would suggest using ping to start then call ssh if things went okay in terms of being able to the the remote box. ping has a default timeout setting.
Example:
Code:
ping -w [timeout in seconds]  -q remotenode
[ $? -eq 0 ]  &&  ssh me@somewhere command ||  echo 'failed to connect'

# 11  
Old 10-16-2017
Actually I am ok with bakunin's proposal.
Just that it still doesn't work. The line just freezes there an does not proceed to the next iteration? I have been waiting for the code to execute as when it is possible.
# 12  
Old 10-17-2017
Quote:
Originally Posted by alvinoo
Actually I am ok with bakunin's proposal.
Just that it still doesn't work. The line just freezes there an does not proceed to the next iteration? I have been waiting for the code to execute as when it is possible.
In this case, may i gently remind you on what i wrote above:

Quote:
Originally Posted by bakunin
If it is that the quoted line just hangs and doesn't finish: start it in the background and have a wait command at the end collecting all the hanging processes.
Save for the wrong usage of the progressive form which should read "collect" instead of "collecting" i still stand by that.

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Expect script hangs Linux

When I run script listed below it causes my Linux to hang. When it freezes I can do totally nothing, move cursor, switch to another terminal or whatever. Linux is just not responding and the only way out I know is a hard reset of PC. #!/bin/bash if ; then echo "one parameter is needed: IP... (3 Replies)
Discussion started by: mass85
3 Replies

2. Shell Programming and Scripting

script hangs when reading from stdin

script: while read inputline; do if ; then if ; then break fi fi done Looks like the script hangs when stdin is empty or contains space. Any ideas on how to circumvent this? is it possible to use getline to process stdin content? (4 Replies)
Discussion started by: ux4me
4 Replies

3. Shell Programming and Scripting

Script Hangs!

Hi, I have script which is based on TCL and expect. It is written to test my code. It usually runs fine for a while and hangs after sometime. Code snippet set l_temp_timeout $timeout OUTPUT_LOG2 2 >>>$expect_out(buffer)<<< OUTPUT_LOG2 2... (2 Replies)
Discussion started by: naveenpn
2 Replies

4. Solaris

script hangs when outputing to /dev/console

I am running solaris 8 on a sparcs box. The system is connected to a lightwave console server. I have a script that hangs when sending output to '/dev/console'. Any ideas? -V (2 Replies)
Discussion started by: vada010
2 Replies

5. UNIX for Dummies Questions & Answers

proceed through a menu-based program with a script?

I am trying to figure out a way to proceed through a menu-based program in UNIX with just one command to execute several steps. Is this possible? From the command prompt I would normally type the name of the program, 'disk_analysis' to start the program and bring up its menu. I would then... (4 Replies)
Discussion started by: nichola$
4 Replies

6. Shell Programming and Scripting

Hi Python and shell script,the script hangs

Hi I need to run a shell script from a TCL script,the shell script in trun will run a python script 1.Tcl script set filename "./GopiRun.sh" 2.GopiRun.sh python ./psi.py $MYSB/test_scripts/delivery/gpy1.py 3.I have my gpy1.py script. Here the problem i am facing is on running... (0 Replies)
Discussion started by: nathgopi214
0 Replies

7. Shell Programming and Scripting

script hangs when a remote server is down

Hi all, I have made a script which logins to remote servers and fetches some data from it. Is is working perfectly when all servers are reachable BUT my problem is -- if in case a server is down (or not reachable), the script hangs. Is there some way, that the script just continues to ssh... (6 Replies)
Discussion started by: vikas027
6 Replies

8. Shell Programming and Scripting

script calling other scripts hangs

I have a script that calls several other scripts in a specified order: # Loop over actions in specified order (STOP_ORDER or START_ORDER) and build and evaluate commands for command in $(eval print '$'${action}_ORDER) do printf "`date`\tExecuting ${action}_${command} = `eval print... (1 Reply)
Discussion started by: rein
1 Replies

9. Linux

Script hangs on the unix server

We have a unix script scheduled to execute once in a day, some times it hangs on the server and never performs its operations, we need to manually kill the process and re-start that script, is there any way to have notification when the script hangs on the server. Thanks & Regards, Murthy. (3 Replies)
Discussion started by: Ramana Murthy
3 Replies

10. Solaris

script hangs-up at exit

I have a script that runs in verbose mode. At the end of the script it displays the final "exit" but then it hangs. What's going on?:( (5 Replies)
Discussion started by: davels
5 Replies
Login or Register to Ask a Question