Guest User

cronjobtimer.sh

a guest
Sep 3rd, 2014
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ## SYNOPSIS ##
  4. # This script takes another script and measures it's runtime, appending it to the same log that the script's stderr and stdout go.
  5. # First argument is the script name, relative to this scripts location.
  6. # All arguments are passed directly to the first argument script.
  7. #
  8. # This script also locks the given script to prevent cronjobs from going to a repeating loop.
  9. #
  10.  
  11. logdirectory=/home/koha/koha-dev/var/log/
  12. logfile=$1".log"
  13. logpath=$logdirectory$logfile
  14. croncommand=$KOHA_PATH"/misc/$@"
  15. lockfile=$KOHA_PATH"/misc/$1.lock"
  16. disableCronjobsFlag=$KOHA_PATH"/misc/cronjobs/disableCronjobs.flag"
  17.  
  18.  
  19. starttime=$(date +%s)
  20. startMsg='Start: '$(date --date="@$starttime" -Iseconds)
  21. printf "$startMsg\n" >> $logpath
  22.  
  23. #Check if cronjobs are disabled by the preproduction to production migration process
  24. if [ -e $disableCronjobsFlag ]; then
  25. echo "Disabled by disableCronjobsFlag" >> $logfile
  26. exit 0;
  27. fi
  28.  
  29. #Lock the cronjob we are running!
  30. if [ -e $lockfile ]; then
  31. echo "Lockfile present" >> $logfile
  32. exit 0;
  33. fi
  34. touch $lockfile
  35.  
  36.  
  37.  
  38. $croncommand 2&>> $logpath
  39.  
  40.  
  41.  
  42. endtime=$(date +%s)
  43. runtime=$((endtime - starttime))
  44. timelog='End: '$(date --date="@$endtime" -Iseconds)"\n"'Runtime: '$(($runtime/60/60))':'$(($runtime/60%60))':'$(($runtime%60))
  45.  
  46. printf "$timelog\n" >> $logpath
  47.  
  48. rm $lockfile
Advertisement
Add Comment
Please, Sign In to add comment