Linux script background monitoring executes the state of the specified program (assuming the program is a dead restart program)

Source: Internet
Author: User

#!/bin/sh

While True
Do

PS | grep "MAIN_3G" | Grep-v "grep" >/dev/null


If ["$?"-ne 0]
Then

ls/root/main_3g >/dev/null

If ["$?"-eq 0]
Then
chmod 777/root/main_3g
/ROOT/MAIN_3G &
echo "main_3g Restart"
Else
echo "main_3g is not exist."
Fi

Fi


PS | grep "MAIN_4G" | Grep-v "grep" >/dev/null


If ["$?

"-ne 0]
Then


ls/root/main_4g >/dev/null


If ["$?"-eq 0]
Then
chmod 777/root/main_4g
/ROOT/MAIN_4G &
echo "main_4g Restart"
Else
echo "main_4g is not exist."
Fi
Fi


Sleep 5


Done


Add the above step command to the/etc/rc.d/rc.local, and add it later.

ls/root/mymonitor.sh >/dev/null
If ["$?

"-eq 0]
Then
chmod 777/root/mymonitor.sh
/root/mymonitor.sh &
echo "Run/root/mymonitor.sh"
Else
echo "/root/mymonitor.sh is not exist."
Fi




Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

Linux script background monitoring executes the state of the specified program (assuming the program is a dead restart program)

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.