Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Script to run a command (such as Laravel's "php artisan schedule:run") at the top of every minute, without Cron
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
"$@" &
# echo "sleeping for $((61-now)) seconds..."
sleep $((61-now))
# example usage:
# topofminute date -u "+%+"

This comment has been minimized.

Copy link

@bhaidar bhaidar commented Sep 9, 2020


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