Tuesday, December 12, 2017

Script timer: run vs pause script execution during certain hours


This quickly became a standard part of my scripts, especially when checking larger lists of sites over days and days,  like the checking the Alexa 1 million for use of 'schema' on the homepage.

Running these scripts from home, there are good times to run a larger amount of traffic over the shared internet connection: at night, usually.

This script snippet has three elements:
  • a  variable to set the hours where it can run
  • setting a variable to the current hour 
  • comparing with a regex match if the hour is in the array, if yes, run, if no, pause
To use it, I edit the hours, start the script in a byobu on server, f6 to logout, check in a few days later and collect the data.

intime=' 00 01 02 03 04 05 06 07 22 23 24 '

while read -r line ; do
    hour=$(date +%H)
    if [[ $intime =~ $hour  ]] ; then
        echo "running now " $( date +%H:%M )
#script to execute, for example curl $line

# --------next part of the timer

else
    echo "sleeping and time is " $( date +%H:%M)
    sleep 10m
fi

No comments:

Post a Comment

Bookmark and Share