0

Here's my situation: I've made a script in a while loop, but sometimes (say after 20-30 loops) it stops unexpectedly. I tried to debug it but I couldn't.

I noticed that it stops while executing a command, and it just doesn't do anything when it stops. Now I was thinking: is there a way to tell to another script when the first script stops and it doesn't execute any command in, say 120 seconds? Maybe by constantly observing the output of the first script and when it's giving no output, the second script kills the first one and makes it start again? Sorry for my bad English hope I was clear.

  • Have a look over at https://stackoverflow.com/questions/16828035/linux-command-to-check-if-a-shell-script-is-running-or-not to find out if a process is running. – mattias Nov 02 '17 at 19:21
  • The "on I/O" dupe is closer inasmuch as you're looking for a timeout to take place only without output. BTW, in general, what you're looking for is called "watchdog" functionality -- where a program gets restarted after a certain amount of time without anyone "petting the watchdog" (resetting the timer). If your program is a daemon, your process supervision system may have its own watchdog support -- systemd does, for example. – Charles Duffy Nov 02 '17 at 19:27
  • I know what's timeout (I'm using it in the buggy script) but I don't want to throw all in another script with timeout because it's a loop and theoretically it can go on forever, and secondly I'm using a counter and I can't make counters go from a script to another... Isn't there another way? – D. Appresti Nov 02 '17 at 19:28
  • Ok I'll try to use watchdog and I'll let you know... if it doesn't work I'll replace all the counters with flag files and count them on the script that calls the other script using the timeout function. What a mindf... Thanks, Charles anyway – D. Appresti Nov 02 '17 at 19:31

0 Answers0