run inotifywait on background

You can run the script with screen or nohup but I'm not sure how that would help since the script does not appear to log its output to any file.

nohup bash </dev/null >/dev/null 2>&1 &


screen -dm bash </dev/null >/dev/null 2>&1 &

Disown could also apply:

bash </dev/null >/dev/null 2>&1 & disown

You should just test which one would not allow the command to suspend or hang up when the terminal exits.

If you want to log the output to a file, you can try these versions:

nohup bash </dev/null >/path/to/logfile 2>&1 &
screen -dm bash </dev/null >/path/to/logfile 2>&1 &
bash </dev/null >/path/to/logfile 2>&1 & disown

I made a 'service' out of it. So I could stop/start it like a normal service and also it would start after a reboot:

This was made on a Centos distro So I'm not if it works on others right away.

Create a file with execute right on in the service directory



# chkconfig: 2345 90 60

case "$1" in
   nohup SCRIPT.SH > /dev/null 2>&1 &
   echo $!>/var/run/
   pkill -P `cat /var/run/`
   rm /var/run/
   $0 stop
   $0 start
   if [ -e /var/run/ ]; then
      echo SCRIPT.SH is running, pid=`cat /var/run/`
      echo SCRIPT.SH is not running
      exit 1
   echo "Usage: $0 {start|stop|status|restart}"

exit 0

Everything in caps you should change to what your script name.

The line # chkconfig: 2345 90 60 makes it possible to start the service when the system is rebooted. this probably doens't work in ubuntu like distro's.