Micky Maus
Micky Maus

Reputation: 15

How can I run a Unix script every hour, but after 4AM?

I would like to let a script run every hour, but only if its after 4AM. My current attempt:

if [ -e filename ] || [ date +%k%M < 400 ]
then don't do anything
else do something 
fi

I am assuming that at 4AM date +%k%M would show 400 or is it 0400? Is there a better way to check if 4AM has been passed?

Cheers

Edit: I'm not able to use cron jobs. The script will run 24/7 and should check if it is after or before 5AM.

Upvotes: 0

Views: 291

Answers (1)

Roberto Paz
Roberto Paz

Reputation: 356

You could use just crontab to set hour limits:

1 4-18 * * * command

This executes "command" between 4 am and 6 pm, at the first minute of every hour.

Upvotes: 1

Related Questions