Comparing system time to specific hours

M

Michael Chernecki

Hi,
I am fairly new to writing Perl code. I need to write a routine that
will redirect website traffic to a maintenance screen between 3am and
4am every night. How do I check a given system date against these
schedule down times.

Thanks
Mike
 
S

Scott W Gifford

I am fairly new to writing Perl code. I need to write a routine that
will redirect website traffic to a maintenance screen between 3am and
4am every night. How do I check a given system date against these
schedule down times.

Use the "localtime" function.

----ScottG.
 
M

Matt Garrish

Michael Chernecki said:
Hi,
I am fairly new to writing Perl code. I need to write a routine that
will redirect website traffic to a maintenance screen between 3am and
4am every night. How do I check a given system date against these
schedule down times.

my ($hr) = (localtime(time))[2];

if (($hr > 3) && ($hr < 4)) { ... }


Matt
 
M

Matt Garrish

Matt Garrish said:
Michael Chernecki said:
Hi,
I am fairly new to writing Perl code. I need to write a routine that
will redirect website traffic to a maintenance screen between 3am and
4am every night. How do I check a given system date against these
schedule down times.

my ($hr) = (localtime(time))[2];

if (($hr > 3) && ($hr < 4)) { ... }

if ( $hr == 3 ) { ... }

Ugh! I should have read that again *before* posting. Don't know what I was
thunking...

Matt
 
J

John J. Trammell

Michael Chernecki said:
I am fairly new to writing Perl code. I need to write a routine that
will redirect website traffic to a maintenance screen between 3am and
4am every night. How do I check a given system date against these
schedule down times.
my ($hr) = (localtime(time))[2];

if (($hr > 3) && ($hr < 4)) { ... }

I'm not sure that does what you want. How about:

if ($hr == 3) { ... }
 
M

Matt Garrish

John J. Trammell said:
Michael Chernecki said:
I am fairly new to writing Perl code. I need to write a routine that
will redirect website traffic to a maintenance screen between 3am and
4am every night. How do I check a given system date against these
schedule down times.
my ($hr) = (localtime(time))[2];

if (($hr > 3) && ($hr < 4)) { ... }

I'm not sure that does what you want.

But an effective way of not running that block, none the less... : )

Matt
 
M

Michael Chernecki

Purl Gurl said:
Most illogical.

Your website is down for maintenance. How will clients connect?

Assuming only selected directories are to be down, leaving
your primary server online, why would you use Perl for
a redirect? Doing so would require a cgi application, yes?

There is no need to jump through a series of inefficient hoops.

Simply write a redirect based on time, which can be included
in an Apache httpd.conf file, an .htaccess file for document
root or any directory or directories. Same applies for other
server types.

Here is an Apache example. The same can be accomplished
for other server types.

RewriteEngine on
RewriteCond %{TIME_HOUR}%{TIME_MIN} >0259
RewriteCond %{TIME_HOUR}%{TIME_MIN} <0401
RewriteRule ^.*$ http://some.server/your/maintain.html


Purl Gurl

Thanks everyone for all the suggestions, based on Scott's original
suggestion of using localtime, I used if ($hour == 3) {...} and it
wortked great.

Purl Gurl - The servers are still running and no directories will be
down. This redirect is in place to prevent dealers from entering an
ordering system during the time that databases are down for
maintenance. Yet, they are still able to visit other areas of the
website.


Thanks
Mike
 
K

krakle

Purl Gurl said:
Michael said:
(snipped)
Thanks everyone for all the suggestions, based on Scott's original
suggestion of using localtime, I used if ($hour == 3) {...} and it
wortked great.
Purl Gurl - The servers are still running and no directories will be
down. This redirect is in place to prevent dealers from entering an
ordering system during the time that databases are down for
maintenance. Yet, they are still able to visit other areas of the
website.


"...redirect website traffic...these schedule[sic] down times."

Work on wording your articles better. =)


Purl Gurl

Why? He asked for a Perl answer not an apache answer (hence the group
he posted to comp.languages.perl.misc). Whether he specified a reason
why the site would be down it irrelevant and none of your buisness,
really it isn't. And either way Scott he would of received the answer.
Stop being so nosy.. Women.....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top