cronjobs_in_seconds.sh
#!/usr/local/bin/bash
PATH=$PATH
TIMES=`date +"%s"`
LOGFILE="/tmp/CRONJOBS-$TIMES-"
CHKPARA=0
if [ -n "$1" ]; then
WAITTIME="$1"
shift
else
CHKPARA=1
fi
if [ -n "$1" ]; then
SCRIPTNAME="$1"
shift
else
CHKPARA=1
fi
if [ ! -f $SCRIPTNAME ]; then
echo "Script file $SCRIPTNAME does not existed."
exit 1
fi
case $WAITTIME in
RANDOM|random) SLEEPSECS=$((RANDOM%60+1))
;;
*) SLEEPSECS=$WAITTIME
;;
esac
if [ $CHKPARA -eq 1 ]; then
echo "Usage: $0 SleepSeconds|RANDOM /Path/to/Script_Name"
echo "Example: $0 15 /root/root_scripts/authlog_banip.sh"
echo " $0 random /root/root_scripts/authlog_banip.sh"
exit 1
else
RUNS=`expr 60 / $SLEEPSECS`
RUNLIMIT=`expr 1 + $RUNS`
LOGFILE="$LOGFILE"`md5 $SCRIPTNAME | awk '{print $4}'`
touch $LOGFILE
for((run=$RUNS; run > 0; run--)); do
echo "$SCRIPTNAME $WAITTIME seconds - run "`expr $RUNLIMIT - $run` >> $LOGFILE
$SCRIPTNAME >> $LOGFILE
echo "====================================" >> $LOGFILE
if [ $run -gt 1 ]; then
sleep $SLEEPSECS
fi
done
rm -f $LOGFILE
fi
/etc/crontab
* * * * * root /Path/to/cronjobs_in_seconds.sh 10 /Path/to/authlog_banip.sh > /dev/null 2>&1
No comments:
Post a Comment