Skip to content

Instantly share code, notes, and snippets.

@gwpl
Last active May 21, 2017 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gwpl/e1d7dc9f9ce1684ff153f36ff45fc440 to your computer and use it in GitHub Desktop.
Save gwpl/e1d7dc9f9ce1684ff153f36ff45fc440 to your computer and use it in GitHub Desktop.
Handy snippet to depending behaviour on hour in bash
echo 'Current hour'
hour=$(date +%H);
if [ $hour -gt 9 -a $hour -lt 23 ]; then echo -n '*'; else echo -n '#'; fi; echo ' '$hour;
echo 'Test around the clock:'
for hour in {0..23} {0..23}; do
if [ $hour -gt 9 -a $hour -lt 23 ]; then echo -n '*'; else echo -n '#'; fi; echo ' '$hour;
done
echo 'If you need to depend on UTC, just add `-u` flag to `date` command'
# Example of depend_on_hour modification, that pauses and resumes bitcoind on given times.
# Purpose? Quieter disks at night :)
# Set this script with cron or systemd-timers
echo 'Current hour'
hour=$(date +%H);
if [ $hour -gt 9 -a $hour -lt 23 ]; then
set -x
killall -v -CONT bitcoind
else
set -x
killall -v -STOP bitcoind
fi;
@gwpl
Copy link
Author

gwpl commented May 21, 2017

This may be also helpful:
pgrep -f 'rsync./path.' -a # to investigate
pkill -CONT -f "rsync./path." # and to catch -CONT or -STOP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment