木头人的gravatar头像
木头人 2017-10-19 23:18:16
linux中shell遇到的坑

     在keepalived+nginx使用的过程中,当nginx崩溃了,keepalived可以重启nginx。使用keepalived来开启nginx要是用shell脚本。但是脚本却报错:

#!/bin/bash
counter=$(ps -C nginx --no-heading|wc -l)
if [ "${counter}" = "0" ]; then
    /usr/local/nginx/sbin/nginx
    sleep 2
    counter=$(ps -C nginx --no-heading|wc -l)
    if [ "${counter}" = "0" ]; then
        /etc/init.d/keepalived stop
    fi
fi

shell脚本中要执行linux命令,有两种方法:

1.使用斜单引号来包裹linux命令。counter=`ps -C nginx --no-heading|wc -l` ,来计算nginx进程的数量;

2.使用$(ps -C nginx --no-heading|wc -l)包裹命令来计算linux命令的值。


打赏

已有1人打赏

最代码官方的gravatar头像
最近浏览
梦醒繁华丶  LV19 2018年4月26日
aa985405715  LV3 2018年2月5日
wgc_jy  LV21 2018年2月2日
低调人  LV38 2017年12月17日
weienqing  LV17 2017年11月20日
coding喵  LV16 2017年11月3日
nsq0006  LV6 2017年11月3日
thisme  LV2 2017年11月2日
程序猿全敏  LV29 2017年11月2日
已注销用户  LV34 2017年10月28日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友