Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

check time of script

SOLVED
Go to Solution
Super Advisor Super Advisor

check time of script

hello,

how can you check the time a script is run;

I want my script to check that it is after 18:00 to ensure the script is not run early

can you help?

Thanks
hello
1 ACCEPTED SOLUTIONS
Highlighted
Honored Contributor Honored Contributor

Re: check time of script

#!/usr/bin/sh

HOUR+$(date "+%H")
if [ $HOUR -lt 18 ]
then
echo "must run after 10:00, current time is $(date "+%H:%M")
exit
fi
3 REPLIES
Honored Contributor Honored Contributor

Re: check time of script

Well, the easiest thing to do would be to schedule the script for a specific time via cron.

This way, you would ensure that it is running after 18:00

man crontab

for details.

Best regards,

Kent M. Ostby
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Highlighted
Honored Contributor Honored Contributor

Re: check time of script

#!/usr/bin/sh

HOUR+$(date "+%H")
if [ $HOUR -lt 18 ]
then
echo "must run after 10:00, current time is $(date "+%H:%M")
exit
fi
Super Advisor Super Advisor

Re: check time of script

Thanks both, Bill has the answer - the job will be setup in cron but I do not wish for the script to be run manually by mistake.
hello