Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Log files in a Date / Time Stamped Directory

Reply
Thread Tools

Log files in a Date / Time Stamped Directory

 
 
Manzoorul Hassan
Guest
Posts: n/a
 
      03-17-2005
I would like to store my logs in a Directory / Subdirectory tree that
corresponds to the date / time the script is executed. For example, if
the script is executed today and noon, then the logs would be stored
under 20050317/1200/

How do I do this?

- manzoor

 
Reply With Quote
 
 
 
 
Brian McCauley
Guest
Posts: n/a
 
      03-17-2005


Manzoorul Hassan wrote:
> I would like to store my logs in a Directory / Subdirectory tree that
> corresponds to the date / time the script is executed. For example, if
> the script is executed today and noon, then the logs would be stored
> under 20050317/1200/
>
> How do I do this?


What have you tried? How did it fail?

 
Reply With Quote
 
 
 
 
Brian McCauley
Guest
Posts: n/a
 
      03-17-2005


Manzoorul Hassan wrote:

> I would like to store my logs in a Directory / Subdirectory tree that
> corresponds to the date / time the script is executed. For example, if
> the script is executed today and noon, then the logs would be stored
> under 20050317/1200/
>
> How do I do this?


perldoc -f localtime

 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      03-17-2005
Manzoorul Hassan <(E-Mail Removed)> wrote:
> I would like to store my logs in a Directory / Subdirectory tree that
> corresponds to the date / time the script is executed. For example, if
> the script is executed today and noon, then the logs would be stored
> under 20050317/1200/
>
> How do I do this?



perldoc -f time
perldoc -f localtime
perldoc -f gmtime
perldoc -f mkdir


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Manzoorul Hassan
Guest
Posts: n/a
 
      03-17-2005
OK, I tried the following for the Date and it works:

#!/usr/bin/perl -l
use Time::localtime;
$time = localtime;

printf ("%04d%02d%02d\n", $time->year+1900, $time->mon+1, $time->mday);
printf ("%02d%02d\n", $time->hour, $time->min);

But I can't store this as a value for my Date and Time Dir to be opened
/ created.

- manzoor

 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      03-17-2005
"Manzoorul Hassan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> OK, I tried the following for the Date and it works:
>


To whom are you speaking? Have you read the posting guidelines for this
group? Please quote an appropirate amount of context.

> #!/usr/bin/perl -l


you forgot use strict; and use warnings;

> use Time::localtime;
> $time = localtime;
>
> printf ("%04d%02d%02d\n", $time->year+1900, $time->mon+1,

$time->mday);
> printf ("%02d%02d\n", $time->hour, $time->min);
>
> But I can't store this as a value for my Date and Time Dir to be

opened
> / created.


Why can't you? What have you tried that failed?

Or do you just mean that you "can't" because printf() prints to the
screen instead of storing to a variable? That's what printf() does.
It's cousin sprintf(), on the other hand, returns the formatted string.
Perhaps that's what you're looking for?

Paul Lalli

 
Reply With Quote
 
Manzoorul Hassan
Guest
Posts: n/a
 
      03-17-2005
well, I was trying to do the following:

$date_val = printf ("%04d%02d%02d\n", $time->year+1900, $time->mon+1,
$time->mday);
opendir(DIR, "$date_val) || die "Cannot open Dir\n";

That didn't work. Now I am trying with the sprintf, but still not
opening.

- manzoor

 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      03-17-2005

"Manzoorul Hassan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> well, I was trying to do the following:
>
> $date_val = printf ("%04d%02d%02d\n", $time->year+1900, $time->mon+1,
> $time->mday);


This is non-sensical. printf() prints a string to the screen.
sprintf() returns the string.

> opendir(DIR, "$date_val) || die "Cannot open Dir\n";
>
> That didn't work.


Of course not. It's a syntax error. Post real code.

> Now I am trying with the sprintf, but still not opening.


Post your real code that is failing, along with the error messages you
are receiving. It's not possible to help you otherwise.

Paul Lalli

 
Reply With Quote
 
Manzoorul Hassan
Guest
Posts: n/a
 
      03-17-2005
#!/usr/bin/perl

use Time::localtime;
$time = localtime;

$date = sprintf ("%04d%02d%02d\n", $time->year+1900, $time->mon+1,
$time->mday);
opendir(DATE_DIR, "$date") || die "Cannot open directory";

closedir(DATE_DIR);

 
Reply With Quote
 
Chris Mattern
Guest
Posts: n/a
 
      03-17-2005
Manzoorul Hassan wrote:

> #!/usr/bin/perl
>
> use Time::localtime;
> $time = localtime;
>
> $date = sprintf ("%04d%02d%02d\n", $time->year+1900, $time->mon+1,
> $time->mday);
> opendir(DATE_DIR, "$date") || die "Cannot open directory";
>
> closedir(DATE_DIR);


And what, exactly, is this code supposed to do? Because, as near as
I can tell, it doesn't do anything, other than die with "Cannot open
directory" if the directory in $date doesn't exist.
--
Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date stamped protection on recent films? Pete L DVD Video 2 03-11-2008 12:39 AM
JPA and time stamped data Chris Ward Java 4 07-24-2007 02:12 PM
Calculating time of employee session from the log date/time stampusing perl Jayesh Kamdar Perl Misc 2 05-25-2005 12:08 AM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Date & Time chooser for java 1.1 - using only the mouse to select time & date Chris Berg Java 0 10-27-2003 10:59 PM



Advertisments