Some of the more functional requirements are relatively simple to consider using the shell script to write, so as to facilitate fast and stable
1. Read the file value, open and close some programs according to the file value 1 or.
A. While:
Do
Done
is an infinite loop.
B. While-read line
Do
Echo $line
Done < value
is to read each line in the file value.
C. if [$line = "0"]; Then
Fi
Is the IF statement, and the left and right sides of the [] blank spaces.
D. if []; Then
elif []; Then
Fi
is a if-else statement.
E.
PS | Grep-v grep | grep Modbusconfig | WC-L
Wc-l is the number of bars used to calculate the result
Grep-v grep is to remove records containing grep in the results
F. #!/bin/sh is using the SH tool in the/bin/directory
#!/bin/SH while : DoCD/sys/class/gpio/gpio26/ whileRead Line DoEcho$lineif[$line ="0"]; ThenKillallPwmoutKillallModbusconfigEchoPwm_duty_cycle ->/tmp/My_fifoelif[$line ="1"]; ThenSN=`PS|grep-Vgrep|grepPwmout |WC-l 'if[$sn-lt1]; ThenCD/modbus/./pwmout &fiSM=`PS|grep-Vgrep|grepModbusconfig |WC-l 'if[$sm-lt1]; ThenCD/modbus/./modbusconfig &fifi Done<valueSleep 1 Done
2. Watchdog daemon, when the target program is not running it will start it
watchdog.sh
get_web_srv_sts () {Ret1=`PS|grep " $"|grep-Vgrep|WC-l ' Ret2=`PS|grep " $"|grep-Vgrep|grep "Z"|WC-l 'if[$ret 1-ge1] && [$ret 2-eq0 ] ThenFun_ret=" up" ElseFun_ret=" Down" fi} while true; Doget_web_srv_sts"Collector_arm" if[$FUN _ret =' up' ] Then Echo "Process Running" Sleep - Else Echo "Process Down" KillallCollector_armSleep -CD/usr/file/SSF./collector_arm&Sleep - fi Done
Shell script usage Record