Shell script usage Record

Source: Internet
Author: User

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

Related Article

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.