asadz
asadz

Reputation: 174

shell scripting help cron job not executing

#!/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

This code runs perfectly on manual testing. But when i couple it with cron it just doesn't do anything. No output file is created.

My cron entries for the script looks like

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

Upvotes: 2

Views: 569

Answers (1)

Max
Max

Reputation: 2131

It looks like you are not setting the working directory, so you may need to give an absolute path for the output file

Upvotes: 1

Related Questions