Created
July 13, 2016 16:26
-
-
Save dzuelke/5cd7e4772120ba098a8427e1efbc61a9 to your computer and use it in GitHub Desktop.
Script to run a command (such as Laravel's "php artisan schedule:run") at the top of every minute, without Cron
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
topofminute() { | |
local now; | |
while true; do | |
now=$(date "+%S") | |
now=${now#0} # strip leading zero for arithmetic operations | |
# run command only if less than ten seconds have passed in the current minute | |
if [[ "$now" -le 10 ]]; then | |
# run command in the background | |
"$@" & | |
fi | |
# echo "sleeping for $((61-now)) seconds..." | |
sleep $((61-now)) | |
done | |
} | |
# example usage: | |
# topofminute date -u "+%+" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
Is this the correct way to go?
topofminute php artisan schedule:run