Skip to content

Instantly share code, notes, and snippets.

Embed
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
#!/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

This comment has been minimized.

Copy link

@bhaidar 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