Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Log files in a Date / Time Stamped Directory (http://www.velocityreviews.com/forums/t891396-log-files-in-a-date-time-stamped-directory.html)

Manzoorul Hassan 03-17-2005 05:06 PM

Log files in a Date / Time Stamped Directory
 
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


Brian McCauley 03-17-2005 05:38 PM

Re: Log files in a Date / Time Stamped Directory
 


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?


Brian McCauley 03-17-2005 05:40 PM

Re: Log files in a Date / Time Stamped Directory
 


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


Tad McClellan 03-17-2005 06:25 PM

Re: Log files in a Date / Time Stamped Directory
 
Manzoorul Hassan <manzoorul.hassan@gmail.com> 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
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Manzoorul Hassan 03-17-2005 07:25 PM

Re: Log files in a Date / Time Stamped Directory
 
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


Paul Lalli 03-17-2005 07:39 PM

Re: Log files in a Date / Time Stamped Directory
 
"Manzoorul Hassan" <manzoorul.hassan@gmail.com> wrote in message
news:1111087502.046821.89690@l41g2000cwc.googlegro 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


Manzoorul Hassan 03-17-2005 08:21 PM

Re: Log files in a Date / Time Stamped Directory
 
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


Paul Lalli 03-17-2005 08:23 PM

Re: Log files in a Date / Time Stamped Directory
 

"Manzoorul Hassan" <manzoorul.hassan@gmail.com> wrote in message
news:1111090872.198833.155360@g14g2000cwa.googlegr 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


Manzoorul Hassan 03-17-2005 08:38 PM

Re: Log files in a Date / Time Stamped Directory
 
#!/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);


Chris Mattern 03-17-2005 08:51 PM

Re: Log files in a Date / Time Stamped Directory
 
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?"


All times are GMT. The time now is 02:24 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.