Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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)

share|improve this question
    
How does it not work in the background ? Does it exit immediately or does it fail to notice changed files or something else ? –  Iain 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

1 Answer 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 $?
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.