我正在使用nohup脚本运行inotify命令,因为inotify停止时,我退出terminal,所以我希望脚本在后台运行。 所以我运行这样的脚本
nohup /path/to/script.sh >/dev/null 2>&1 &
问题不是nohup每次创build新文件时都要创build新的进程。 我怎样才能避免这个或任何其他build议方法来完成我的任务。
我想在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"
你要么lock ,要等待以前的过程结束…或者你kill了以前的过程…没有你正在运行的script详细信息…我们不能真正告诉你很多。
理想情况下,你的脚本会检查某种循环中的某些东西。 如果有事情要做,那就做,然后在每一次迭代中做一些睡眠。 有些东西没有正确地结束。