Bash 发现进程有问题

Bash 发现进程有问题

我只是想让一个脚本运行或不运行或出错。

我的计划很简单:

Check is spotifyd running (y/n)
if yes
say "It's running"
if no
try to run

did it work (y/n)
if yes
say It started
if no
say it gave an error

(更容易理解的版本:如果spotifyd给出错误,则不要启动守护进程。因此,如果它不运行,我们将尝试运行。如果仍然不运行,则说错误)

这是我的代码(我是菜鸟,所以你的眼睛可能会流血)

date=$(date "+%d.%m.%Y %H.%M")

if [ "spotifyd" == $(ps aux | grep spotifyd | grep "0.1" | awk '{print $11}') ]; then
    echo "[$date] Procces is allready running"
    exit
elif [ "" == $(ps aux | grep spotifyd | grep "0.1" | awk '{print $11}') ]; then 
    spotifyd 
    exit
elif [ "spotifyd" == $(ps aux | grep spotifyd | grep "0.1" | awk '{print $11}') ]; then 
    echo "Procces has started"
    exit
elif [ "err" == $(ps aux | grep spotifyd | grep "0.1" | awk '{print $11}' || echo "err") ]; then
    echo "[$date] Procces couldn't start. Check the procces' manual" 
    exit
fi

相关内容