I realize that a single zombie process like this is nothing to worry about, I just want a more professional outcome (no zombie) from my code.

My cron job calling a shell script produces a single zombie of the shell script only the first time it launches the shell script; that is, the first time AFTER the 'tail -f' "catches up" when initially starting. This is a @reboot cron job, so at reboot there will be no zombie of the shell script produced even though the cron job launches the shell script many times, as long as the 'tail -f' has more lines immediately available from the file it is montoring (/var/log/kern.log). Once the cron job 'tail -f' catches up to to the last line of kern.log, the zombie will get created the next time afterwards that the 'tail -f | grep ...|xargs myshellscript' produces output. Once that single zombie is created, no more ever get added to it regardless of how many times the cron entry produces further output.

I've tried the obvious of modifying the cron entry to launch the shell script preceded with 'nohup' and followed by '&' but that zombie still gets made.

crontab entry:

@reboot nice -n15 /usr/bin/tail -F -n 0 /var/log/kern.log |/bin/grep --line-buffered ' SRC=' |stdbuf -o0 /bin/grep -v 'SRC=10\.' |stdbuf -o0 grep -v 'SRC=0\.0\.0\.0' |stdbuf -o0 grep -v 'SRC=127.0\.0\.1' |stdbuf -o0 /bin/grep -v 'SRC=192\.168\.' |stdbuf -o0 awk '{for (i=4;i<=NF;i++) {if ($i ~ "^SRC=") {{gsub("SRC=","",$i); printf $i" \""} printf "kern.log "$1" "$2" "$3; for (i=i;i<=NF;i++) {if ($i ~ "^PROTO=" || $i ~ "^SPT=" || $i ~ "^DPT") {printf " "$i}} print "\""}}}' |xargs -l1 /home/homeowner/blacklistme.sh >/dev/null 2>&1

Whether /home/homeowner/blacklistme.sh ends with or without an "exit" command doesn't prevent that zombie, either.

This is part of a firewalling project I'm sharing on GitHub aimed toward protecting Linux home surveillance and automation owners. More info at https://github.com/kenneth558/robust-linux-firewalling-scripting. Thanks to any who can help me!

Your Answer

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

Browse other questions tagged or ask your own question.