Linux 如何在启动和关闭时启动和停止bash脚本?

Linux 如何在启动和关闭时启动和停止bash脚本?,linux,bash,shell,ubuntu-14.04,Linux,Bash,Shell,Ubuntu 14.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 }

这是一个监视一个文件并通知更改的脚本

#!/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

我也运行了这个程序,并将它添加到
/etc/init.d
中,它仍然不允许系统关闭,我认为这与信号有关,就像你实际想要的
inotify
。你能帮我用
inotify
监视一个文件的语法吗占领者你尝试了什么?把你的问题粘贴到谷歌上,我马上就能得到两个跨站点的副本;和