2011-10-21 17 views
2
#!/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ジョブが実行されない

あなたが作業ディレクトリを設定していないように見えます

+0

を参照してください。ここで説明されているエラーhttp://linux-junky.blogspot.com/2010/10/debugging-cronjobs.html –

答えて

1

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

ようなスクリプトのための私のcronエントリが見え、出力ファイルの絶対パスを与える必要があるかもしれませんので、

+0

ありがとうございました絶対パスの問題については、コードは正常に動作しています – asadz

+0

crontabで設定されたパスに頼るのではなく、awkコマンドの絶対パスを指定する方が安全です – Max

関連する問題