#!/bin/bash
#!/bin/sh
# Need help
__help() { echo "$0 [ stop|start ]" 1>&2; exit 1; }
# Not enough args to run properly
[ $# -ne 1 ] && __help
# See what we're called with
case "$1" in
start) # Start sniffer as root, under a different argv[0] and make it drop rights
s=$(/usr/local/sbin/tcpdump -n -nn -f -q -i lo | awk 'END {print NR}')
echo "$s" > eppps_$(/bin/date +'%Y%m%d%H%M')
;;
stop) # End run, first "friendly", then strict:
/usr/bin/pkill -15 -f /usr/local/sbin/tcpdump >/dev/null 2>&1|| { sleep 3s; /usr/bin/pkill -9 -f /usr/local/sbin/tc$
;;
*) # Superfluous but show we only accept these args
__help
;;
esac
exit 0
此代码在手动测试中运行完美。但是当我将它与cron耦合时,它并没有做任何事情。没有输出文件被创建。shell脚本帮助cron作业未执行
的脚本我的cron条目看起来像
http://postimage.org/image/1pztgd6xw/
见错误在这里解释http://linux-junky.blogspot.com/2010/10/debugging-cronjobs.html –