Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
cancel
Showing results for 
Search instead for 
Did you mean: 

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
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
Highlighted
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