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



       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" ]
       mkfifo "$FIFO"

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

      while read date time file
       on_event $date $time $file &
       done < "$FIFO"

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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