[英]how to start and stop a bash script on startup and shutdown?
這是用於監視一個文件並通知更改的腳本
#!/usr/bin/env bash
update_sha()
{
sha="sha512sum /bin/myfile"
}
update_sha
previous_sha=$sha
compare()
{
update_sha
if [[ $sha != $previous_sha ]] ; then
notify-send "change detected"
build
previous_sha=$sha
fi
}
trap exit SIGQUIT
while true; do
compare
sleep 1
done
我叫腳本filecheck.sh
。 跑了nohup ./filecheck.sh &
,它沒有任何問題地運行,但是直到您關閉系統后它才運行,所以我以為我把它添加到/etc/init.d
並更新了它。 但是,當我嘗試重新啟動時,腳本繼續運行並沒有被殺死,因此我不得不關閉系統。 任何有關如何在關機時終止腳本的幫助將不勝感激。
您實際上並沒有運行sha512sum
; 您需要用命令替代。 編寫此腳本的正確方法:
get_sha()
{
sha512sum /bin/myfile
}
previous_sha=$(get_sha)
compare()
{
current_sha=$(get_sha)
if [[ $current_sha != $previous_sha ]] ; then
notify-send "change detected"
build
previous_sha=$currentsha
fi
}
trap exit SIGQUIT
while true; do
compare
sleep 1
done
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.