DATE_START="" #action.circulation.xact_finish date to start with; passed as a parameter to psql
MAX_DURATION_MINUTES="" #Do not call psql again after this many minutes
MAX_DATE="" # if set, do not process circs whose action.circulation.xact_finish exceeds this date
+INCREMENT="1 day"
while [ $# -gt 0 ] ; do
case $1 in
--start) DATE_START="$2"
--end) MAX_DATE="$2"
shift
;;
+ --increment) INCREMENT="$2"
+ shift
+ ;;
*) shift
;;
esac
EPOCH_NOW=$EPOCH_START
function day_increment {
- DAY_TO_INCREMENT=$(date --date="$DAY_TO_INCREMENT + 1 day" '+%Y-%m-%d')
+ DAY_TO_INCREMENT=$(date --date="$DAY_TO_INCREMENT + $INCREMENT" '+%Y-%m-%d')
};
while [[ $EPOCH_NOW -lt $EPOCH_STOP ]] ; do
DAY_TO_INCREMENT=$DATE_START
day_increment
DATE_END=$DAY_TO_INCREMENT
- if [ -n "$MAX_DATE" -a $DATE_START \> $MAX_DATE ]; then
- echo "Reached max date of $MAX_DATE; exiting"
- break;
+ if [ -n "$MAX_DATE" -a $DATE_END \> $MAX_DATE ]; then
+ echo "Reached max date of $MAX_DATE; truncating END_DATE"
+ END_DATE=$MAX_DATE
+ # tell the script to stop after this pass
+ EPOCH_STOP=$(date '+%s')
fi;
echo "Beginning $DATE_START -- $DATE_END ..."
psql -U evergreen --file=purge_circulations.psql --quiet --variable=ts_start="'$DATE_START'" --variable=ts_end="'$DATE_END'"
DATE_START=$DAY_TO_INCREMENT
EPOCH_NOW=$(date '+%s')
done
+