A simple watchdog script with problems in SCO and Aix

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.