1748098 Members
5820 Online
108758 Solutions
New Discussion юеВ

Re: check time of script

 
SOLVED
Go to solution
lawrenzo_1
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
3 REPLIES 3
Kent Ostby
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"
Bill Hassell
Honored Contributor
Solution

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


Bill Hassell, sysadmin
lawrenzo_1
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