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 am using nohup for the script run inotify command, because inotify stop when I exit from terminal so I want the script to run on background. so I run the script like this

nohup  /path/to/script.sh >/dev/null 2>&1 &

the problem is not nohup create new process every time the new file created by inotify. how I can avoid that or any other suggestion method to accomplish my task.

the script I want to run at backgorund

      #!/bin/sh


      DIR="/opt/data/"
      EVENTS="moved_to"
      FIFO="/tmp/inotify2.fifo"

       on_event() {
       local date=$1
       local time=$2
       local file=$3

         sleep 5


       /opt/nfdump/bin/nfdump -qr "$DIR""$file" -o extended | perl -i -p -e 'use    Socket; s#(\d{1,3}(\.\d{1,3}){3})\b#gethostbyaddr(inet_aton($1),AF_INET) or    sprintf($1)#egi' > /opt/nfdump-ascii/nfdump-ascii."$date"."$time".log
             }

      # MAIN
      if [ ! -e "$FIFO" ]
       then
       mkfifo "$FIFO"
       fi

        inotifywait -m -e "$EVENTS" --timefmt '%Y-%m-%d %H:%M:%S' --format '%T %f'  "$DIR" > "$FIFO" &
        INOTIFY_PID=$!


      while read date time file
       do
       on_event $date $time $file &
       done < "$FIFO"
share|improve this question

1 Answer 1

you either lock and wait for the previous process to end... or you kill the previous process... Without details on the script you are running... We can't really tell you much.

Ideally your script would check something in some kind of loop. If there was something to do, it would do it, and then do some kind of sleep at each iteration. Something is not ending properly.

share|improve this answer
    
thanks, I have added the actual script. –  Daniel Sep 20 '13 at 20:17

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.