【发布时间】:2017-03-27 16:57:04
【问题描述】:
这是一个监控一个文件并通知更改的脚本
#!/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,我更新了它。但是当我尝试重新启动时,脚本继续运行并且没有被杀死,我不得不关闭我的系统。任何有关如何在关机时终止脚本的帮助将不胜感激。
【问题讨论】:
-
听起来你真的想要
inotify。 -
你能帮我了解使用
inotify监视文件的语法吗,调用myfile进行更改,echo如果发生更改 -
你尝试了什么?将您的问题粘贴到 Google 会立即让我获得两个跨站点副本; superuser.com/questions/181517/… 和 serverfault.com/questions/1669/…
标签: linux bash shell ubuntu-14.04