Re: check time of script (82 Views)
Reply
Super Advisor
lawrenzo_1
Posts: 560
Registered: ‎06-06-2003
Message 1 of 4 (82 Views)
Accepted Solution

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
Honored Contributor
Kent Ostby
Posts: 1,836
Registered: ‎09-26-2000
Message 2 of 4 (82 Views)

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"
Honored Contributor
Bill Hassell
Posts: 14,210
Registered: ‎05-29-2000
Message 3 of 4 (82 Views)

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
lawrenzo_1
Posts: 560
Registered: ‎06-06-2003
Message 4 of 4 (82 Views)

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
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.