Automatic restart of monitoring program with Shell script

Source: Internet
Author: User

Very few shell scripts, recently wrote a shell script, encountered some problems, unexpectedly was tossing for a long while. These errors are too low and should not be. While there is now time, the entire process of executing the shell script is recorded, which is convenient for later reference.

First, let's take a look at the content of the shell script that was written to automatically restart the process after monitoring a program crash.

#!/bin/bashwhile Truedo     procnum= ' ps-ef|grep "test" |grep-v grep|wc-l '   if [$procnum-eq 0]; then       /home/tes t&   fi   sleep 30done


-eq means equal to 0, which is used to determine if the test is still in the running state. Monitor/home/test This program is running.

Second, because the program is written on the window, we have it (name with run._start.sh) after the copy to Linux need to give it permission to operate

chmod 777 run_start.sh

Third, we will start the program

./run_start.sh &

Remember to add &, or else the window is back, and the script exits.

Third, the discovery of the operation of the error "-bash:./run_start.sh:/bin/bash^m:bad Interpreter: There is no file or directory", according to the hint, I thought that no this shell was not installed, so I could not find "/bin/bash" , in fact, understand the error, is not recognized on Linux Windows Doc format. Remember later, if you encounter this bad interpreter error, be sure to convert the characters, the method is as follows:

1) Edit Error file
VI run_start.sh

2) View this format (error file format is Dos)
: Set FF
3) Modify the format
: Set Ff=unix

4) Save exit
: wq!

Four, re-run the script, you can see the normal

Automatic restart of monitoring program with Shell script

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.