A simple watchdog script that automatically restarts a process when it is stopped. The script is as follows: 1get_web_srv_sts ()
2 {
3 ret = 'ps-AEF | grep "$1" | grep-V grep | WC-l'
4
5 case $ RET in
6 0)
7 fun_ret = "down"
8 ;;
9 1)
10 fun_ret = "up"
11 ;;
12 *)
13 fun_ret = "error: $ RET instances running"
14 ;;
15 esac
16}
17
18
19 get_web_srv_sts "./process1"
20 if [$ fun_ret = 'up']
21 then
22 echo "process1 running"
23 else
24./process1
25 sleep 10
26 FI
27
The command can be executed normally under SCO, but there is a problem with the command execution under Aix. the following error is returned in 20 rows: A test command parameter is not valid.
Then, change the 20 rows to if ["$ fun_ret" = 'up'] To run normally, but each time the process is considered not started (even if it is already started)
After many experiments, we found that WC-l was used when the process was started in SCO, and the result was:
1
In Aix, when the process is started and WC-L is used, the result is:
1
There are a lot of spaces in front, so it is incorrect to use case to judge. Then, we changed the 3rd rows to the following method:
Ret = 'ps-AEF | grep "$1" | grep-V grep | WC-L | SED's // G'
It is correct to remove spaces and then compare them.