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

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

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

Post 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,
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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...
User avatar
SpecialK
Forum Commoner
Posts: 96
Joined: Mon Sep 18, 2006 3:49 pm

Post 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.
blackbeard
Forum Contributor
Posts: 123
Joined: Thu Aug 03, 2006 6:20 pm

Post 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
Post Reply