1

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"
Daniel
  • 13
  • 7

1 Answers1

0

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.

Daniel Widrick
  • 3,418
  • 2
  • 12
  • 26