我有一个脚本sh startAWS.sh
。
最重要的是,我检查了这一点:
if [[ `ps -acx|grep postgres|wc -l` < 1 ]]; then
echo "You need to start your Postgres service to run this script."
ps -acx|grep postgres|wc -l
exit 0
fi
当我运行时,我得到了
⚡️ laravel sh startAWS.sh
You need to start your Postgres service to run this script.
6
嗯...什么...🤦🏻♂️
我的 Postgres 正在运行,不应执行 echo。
显示6
,并且6不小于1,该代码不应被执行。
有谁知道为什么我的 echo 打印出来了?
最佳答案
您需要执行数字比较,因此在检查中使用 -lt 或 -gt。
if [[ `ps -acx|grep postgres|wc -l` -lt 1 ]];
关于linux - 通过 bash 脚本检查服务是否正在运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55172819/