Page 1 of 1

How do I make a script run once a year between certain hours

Posted: Tue Nov 28, 2006 10:38 am
by impulse()
Hello.

I'm trying to create a script that will deny access to services from external locations temporarily while server maintainance is run. I can think of a few ways to do this, either by shutting down the HTTPD or altering the firewall rules to DENY access to external sources. This isn't the problem though, the script has to be a shell script which will run between 23:00 - 0:00 once a year at which point the external source connections are denied. I'm assuming I'm going to have to use a unix timestamp to perform this but I'm not sure how I'm going to run the calculation to perform this. Can someone throw me a suggestion please?

Stephen,

Posted: Tue Nov 28, 2006 10:40 am
by timvw
Simply write a script that gets the current time.. and see if that time is in the 'do something interval'.. In which language are you going to write the script?

And then add an entry to your crontab to make sure the script is actually executed at those times...

Posted: Wed Nov 29, 2006 11:32 am
by SpecialK
If you setup your cron job to run on a certain day in a certain month you wouldn't have to do that much PHP checking with the time.

It all depends how often you are willing to set the cron job to run. It sounds to me like timvw is suggesting if the cron job is run daily, then to do a check before anything is attempted.

The more often the job is run, the more wasteful it is since it's only running once a year.

Posted: Mon Dec 18, 2006 1:41 pm
by blackbeard
Write two scripts, one to stop the web server, the other to start it.

Set up two cron jobs, one for the stop script, one for the start up script.

Here's a link on how to use crontab: http://www.computerhope.com/unix/ucrontab.htm