Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ## SYNOPSIS ##
- # This script takes another script and measures it's runtime, appending it to the same log that the script's stderr and stdout go.
- # First argument is the script name, relative to this scripts location.
- # All arguments are passed directly to the first argument script.
- #
- # This script also locks the given script to prevent cronjobs from going to a repeating loop.
- #
- logdirectory=/home/koha/koha-dev/var/log/
- logfile=$1".log"
- logpath=$logdirectory$logfile
- croncommand=$KOHA_PATH"/misc/$@"
- lockfile=$KOHA_PATH"/misc/$1.lock"
- disableCronjobsFlag=$KOHA_PATH"/misc/cronjobs/disableCronjobs.flag"
- starttime=$(date +%s)
- startMsg='Start: '$(date --date="@$starttime" -Iseconds)
- printf "$startMsg\n" >> $logpath
- #Check if cronjobs are disabled by the preproduction to production migration process
- if [ -e $disableCronjobsFlag ]; then
- echo "Disabled by disableCronjobsFlag" >> $logfile
- exit 0;
- fi
- #Lock the cronjob we are running!
- if [ -e $lockfile ]; then
- echo "Lockfile present" >> $logfile
- exit 0;
- fi
- touch $lockfile
- $croncommand 2&>> $logpath
- endtime=$(date +%s)
- runtime=$((endtime - starttime))
- timelog='End: '$(date --date="@$endtime" -Iseconds)"\n"'Runtime: '$(($runtime/60/60))':'$(($runtime/60%60))':'$(($runtime%60))
- printf "$timelog\n" >> $logpath
- rm $lockfile
Advertisement
Add Comment
Please, Sign In to add comment