[英]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.