shell脚本使用记录
2015-07-13 16:58
543 查看
一些比较功能需求比较简单的可以考虑使用shell脚本来写,这样可以方便快捷稳定
1. 读取文件值,根据文件值1 或 0 来开启和关闭某些程序
a. while :
do
done
是无限循环。
b. while read line
do
echo $line
done < value
是读取文件value中的每行。
c . if [ $line = "0" ]; then
fi
是if语句,[]内左右两边都要留空格。
d. if []; then
elif []; then
fi
是if-else语句。
e.
2. watchdog 守护精灵,当目标程序不在运行时就会启动它
watchdog.sh
1. 读取文件值,根据文件值1 或 0 来开启和关闭某些程序
a. while :
do
done
是无限循环。
b. while read line
do
echo $line
done < value
是读取文件value中的每行。
c . if [ $line = "0" ]; then
fi
是if语句,[]内左右两边都要留空格。
d. if []; then
elif []; then
fi
是if-else语句。
e.
ps | grep -v grep | grep modbusConfig | wc -l wc -l 是用来计算结果的条数 grep -v grep是去掉结果中包含grep的记录 f. #!/bin/sh 是使用/bin/目录下的sh工具
#!/bin/sh while : do cd /sys/class/gpio/gpio26/ while read line do echo $line if [ $line = "0" ];then killall pwmOut killall modbusConfig echo pwm_duty_cycle 100 > /tmp/my_fifo elif [ $line = "1" ];then sn=`ps | grep -v grep | grep pwmOut | wc -l` if [ $sn -lt 1 ];then cd /modbus/ ./pwmOut & fi sm=`ps | grep -v grep | grep modbusConfig | wc -l` if [ $sm -lt 1 ];then cd /modbus/ ./modbusConfig & fi fi done < value sleep 1 done
2. watchdog 守护精灵,当目标程序不在运行时就会启动它
watchdog.sh
get_web_srv_sts() { ret1=`ps | grep "$1" | grep -v grep | wc -l` ret2=`ps | grep "$1"|grep -v grep | grep "Z"|wc -l` if [ $ret1 -ge 1 ] && [ $ret2 -eq 0 ] then FUN_RET="UP" else FUN_RET="DOWN" fi } while true; do get_web_srv_sts "collector_arm" if [ $FUN_RET = 'UP' ] then echo "process running" sleep 60 else echo "process down" killall collector_arm sleep 60 cd /usr/file/ssf ./collector_arm& sleep 60 fi done
相关文章推荐
- shell脚本操作mysql数据库,使用mysql的-e参数可以执行各种sql的(创建,删除,增,删,改、查)等各种操作
- 运维经验分享(一)-- Linux Shell之ChatterServer服务控制脚本
- 运维经验分享(一)-- Linux Shell之ChatterServer服务控制脚本
- websocket shell
- linux中shell变量$#,$@,$0,$1,$2的含义解释
- 工作中常用shell之ssh登陆不用输入"yes"
- IFileDialog-》IServiceProvider-》IShellView-》IFolderView-》IShellItemArray
- Pivotal Gemfire gfsh shell的使用(2)
- Linux学习笔记(13)——shell scripts
- linux执行shell脚本
- RedHat Linux Shell常用命令(多数也适用于Unix和AIX)
- 更改git bash默认的路径
- shell学习四十六天----文件系统的空间信息df和du命令
- Android adb shell 命令
- linux shell 字符串操作(长度,查找,替换,匹配)详解
- shell学习四十五天----xargs
- shell中$0,$?,$!等的特殊用法
- Git bash 操作记住密码
- shell
- 解决shell脚本中 echo 怎么写入换行到文件