#!/bin/bash trap "exit" INT basedir=`dirname "$0"` cd "$basedir/.." resurrfp=".pcresurrectdone" cmdlogfp="peerscrawl.log" logfp="pcloop.log" resdom=25 # day of month when (or after when, if it has not been done already) to execute peerscrawl.php with a gracetime of 2 months function log { echo `date "+%Y-%m-%d %H:%M:%S.%N"` "${1}" >> "${logfp}" } while true; do dom=$((`date "+%d"`+0)) [ $dom -lt $resdom -a -f "$resurrfp" ] && rm "$resurrfp" if [[ ($dom -ge $resdom ) && !(-f "$resurrfp") ]]; then # use a gracetime of 2 months touch "$resurrfp" log "### Starting peerscrawl.php with a 2 months gracetime ###" ./peerscrawl.php -g 2M -e peerscrawl.exclude &> $cmdlogfp else # use the default gracetime log "### Starting peerscrawl.php with the default gracetime ###" ./peerscrawl.php -e peerscrawl.exclude &> $cmdlogfp fi tail $cmdlogfp >> $logfp log "### THE END ###" done exit 0;