shell脚本帮助cron作业不执行

时间:2011-10-21 09:51:52

标签: shell scripting cron

#!/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结合起来时,它什么也没做。没有创建输出文件。

我的脚本的cron条目看起来像

http://postimage.org/image/1pztgd6xw/

1 个答案:

答案 0 :(得分:1)

看起来您没有设置工作目录,因此您可能需要为输出文件提供绝对路径