老师您好 我遇到了个 很奇怪的问题
我虚拟机上装了nginx 我把它给停止了
我直接在终端输入echo $(ps aux|grep nginx | grep -v grep | wc -l) 是等于0
可是我在shell脚本里打印确是2
[root@VM_0_12_centos shellfile]# ps aux|grep nginx
root 30657 0.0 0.0 112704 976 pts/0 S+ 14:47 0:00 grep --color=auto nginx
[root@VM_0_12_centos shellfile]# echo $(ps aux|grep nginx | grep -v grep | wc -l)
0
[root@VM_0_12_centos shellfile]# sh ziqi_nginx.sh
process:2
[root@VM_0_12_centos shellfile]# cat ziqi_nginx.sh
#!/bin/bash
nginx_process_num=$(ps aux|grep nginx | grep -v grep | wc -l)
echo "process:$nginx_process_num"
if [ $nginx_process_num -eq 0 ];then
echo "nginx down"
/usr/local/nginx/sbin/nginx
echo "nginx start"
fi
[root@VM_0_12_centos shellfile]#