0

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)

jroeleveld
  • 111
  • 1
  • 2
  • How does it not work in the background ? Does it exit immediately or does it fail to notice changed files or something else ? – user9517 Mar 29 '13 at 21:36
  • I simply get no output. The 'ftpscript' is not executed, and nothing is written to the specified logfile... – jroeleveld Mar 29 '13 at 22:43

2 Answers2

2

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 $?
symcbean
  • 19,931
  • 1
  • 29
  • 49
0

Best way to do this is with systemd service.

Check out my answer in this stackoverflow thread:

https://stackoverflow.com/a/68724395/10914512