为什么这个bash脚本会产生错误?

时间:2018-05-09 06:57:50

标签: bash

这个简单的脚本 - 检查进程是否正在运行,然后发送电子邮件,如果不是 - 工作正常:

#!/bin/bash

if pgrep -f  "ghost.py" > /dev/null
then
    echo "Running" > /dev/null
else
    echo "Looks like ghost.py stopped" | mail -s "ghost.py down" shaney.jones@gmail.com
fi

但是,我尝试在那里检查两个脚本的OR运算符失败了:

#!/bin/bash

if [ pgrep -f  "ghost.py" ] || [ pgrep -f "ghost2.py" ] > /dev/null
then
    echo "Running" > /dev/null
else
    echo "Looks like a script stopped" | mail -s "Script down" shaney.jones@gmail.com
fi

错误只是说' -bash:[: - f:二元运算符预期'

1 个答案:

答案 0 :(得分:0)

删除括号,因为它完全是另一个命令(通常等同于test):

if pgrep -f  "ghost.py" || pgrep -f "ghost2.py" > /dev/null
then
  # Your stuff

有关help test命令的详细信息,请参阅man test[

相关问题