Run inotifywait in background
I tried literally ALL ways to get this script running in the background (as startup script, as daemon, etc.).
The problem is that this script works in the terminal, but not in the background:
#!/bin/sh
while /usr/local/bin/inotifywait --format '%T %w %e %f' --timefmt '%H:%M:%S %e/%m/%y' --recursive --quiet --outfile /root/watchscript_logs/log /volume1/homes/admin
do
/opt/bin/bash /root/ftpscript.sh
done
I have been trying this on a Synology NAS (DSM 4.2, Linux 2.6.32.12)
Solution 1:
I tried literally ALL ways to get this script running in the background (as startup script, as daemon, etc.)
....but you've not shown us any of the code which you used.
The 'ftpscript' is not executed, and nothing is written to the specified logfile
Did you check if the process you started was still running? What logfile? The code you've shown doesn't write any log files.
It would have helped if you had (also) provided some details of which linux this relates to.
Here's a sys V init script which should do the trick (if you know how to deploy it)....
#!/bin/sh
if [ -f /etc/init.d/functions ] ; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
. /etc/rc.d/init.d/functions
else
exit 0
fi
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
RETVAL=0
start() {
gprintf "Starting inotify monitor: "
RETVAL=1
daemon YOURSCRIPT.sh
RETVAL=$?
return RETVAL
}
stop() {
gprintf "Stopping inotify monitor: "
killproc YOURSCRIPT.sh
RETVAL=$?
return RETVAL;
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
gprintf "Usage: %s {start|stop|restart}\n" "$0"
exit 1
esac
exit $?