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