Skip to content

Instantly share code, notes, and snippets.

@dzuelke
Created July 13, 2016 16:26
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dzuelke/5cd7e4772120ba098a8427e1efbc61a9 to your computer and use it in GitHub Desktop.
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
#!/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 "+%+"
@bhaidar
Copy link

bhaidar commented Sep 9, 2020

Hello,

Is this the correct way to go?

topofminute php artisan schedule:run

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