カールコマンドを使用してウェブサイトを継続的にテストするこのシェルスクリプトを改善する方法はありますか? [閉鎖]

カールコマンドを使用してウェブサイトを継続的にテストするこのシェルスクリプトを改善する方法はありますか? [閉鎖]

以下のスクリプトは、curlコマンドを使用してバージョンで失敗したEメールを減らした後、コマンドを使用して失敗したときにMuttを介して特定のWebサイトとEメールをテストし続けますping

改善する方法はありますか?

次のように:

#!/bin/bash
while true; do
    date > /tmp/sdown.txt
    if curl -fI "given.website.com" 1>& /dev/null ;
    then
        sleep 1
        :
    else
        mutt -s "Website Down!!!" [email protected] < /tmp/sdown.txt
        sleep 10
    fi
done

ベストアンサー1

まず、:後で必要ありませんsleep 1

第二に、他の理由で一時ファイルが必要ない場合は、date必要に応じて簡単に使用できます。したがって、このスクリプトは次のように単純化できます。

#!/bin/bash
while true; do
    if curl -fI "given.website.com" 1>& /dev/null; then
        sleep 1
    else
        date | mutt -s "Website Down!!!" [email protected]
        sleep 10
    fi
done

おすすめ記事