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

(簡単なバージョン:Spotifyでエラーが発生した場合はデーモンを起動しないでください。したがって、実行されていない場合は実行してみます。それでも実行されない場合はエラーと言います。)

私のコードは次のとおりです。 (私は初心者なので目が咲くことがあります。)

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

ベストアンサー1

おすすめ記事