I have a scheduled shell script running in a distributed environment. There are some scenarios where the process might get killed by some other processes. But I need the process to return 0 even after the failure/killed. Is there anyway to implement it in bash?
Asked
Active
Viewed 442 times
0
-
1Can you change how the script is called? I am thinking this should work. `( somescript.sh || true )` – Aaron Copley Mar 23 '18 at 14:14
-
I know this will work but I can't start the process using this command. – pkgajulapalli Mar 23 '18 at 14:16
-
Maybe you can use `trap` to exit 0 on any signal? Sorry, I am just spit-balling. – Aaron Copley Mar 23 '18 at 14:22
2 Answers
1
Depends on the signal. Bash allows you to trap with the trap
command, but if your script is being killed with SIGKILL
(9), it is uninterruptible and untrappable.

brent
- 3,521
- 3
- 26
- 37
0
It sounds like this may be a case for some sort of watchdog process similar to how keepalived tracks processes.
At the simplest, the command pidof might be your friend here.

JohnA
- 586
- 3
- 13