Unable to create logfile with local time stamp using perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unable to create logfile with local time stamp using perl
# 1  
Old 02-06-2012
Unable to create logfile with local time stamp using perl

Hello All,

Morning,

I am facing problem with my code while creating a log with name as current time stamp using perl. Here is the code.
Code:
#!/usr/bin/perl
my $time=localtime;
my ($day,$month,$date,$tm,$year)=split(/ /,$time);
my $stamp=$year."_".$month."_".$date;
my $logdir="SAP_IN_".$stamp;
my $LOGFILE = "E:/pearl/$logdir.log" ;

print " Log file name is : $LOGFILE ";

out put:
Code:
E:/pearl/SAP_IN_12:09:04_Feb_.log

It should be
Code:
E:/pearl/SAP_IN_12:09:04_Feb_3.log.

I think value of localtime gives date in single digit hence split is failing to get value. But this code works if date in 2 digit.

Can some one help me to correct the code?

Thanks
Krsna..

Last edited by Franklin52; 02-06-2012 at 06:46 AM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 02-06-2012
Code:
#!/usr/bin/perl
my $time=localtime;
my ($day,$month,$date,$tm,$year)=split(/\s+/,$time);
my $stamp=$tm."_".$month."_".$date;
my $logdir="SAP_IN_".$stamp;
my $LOGFILE = "E:/pearl/$logdir.log" ;

print "Log file name is : $LOGFILE\n";

# 3  
Old 02-06-2012
Unable to create logfile with local time stamp using perl

Thanks a lot Bala,

This is perfect one working fine. Just want to know what is exact meaning of split(/\s+/,$time); what is the significance of pattern "/s+/".
Please explain.

Thanks
Krsna..
# 4  
Old 02-06-2012
\s matches all whitespaces (tabs, newline, space...)
+ is a quantifier which tells perl to search for one or more of \s.
This User Gave Thanks to balajesuri For This Post:
# 5  
Old 02-06-2012
Thanks a lot Bala,

Simply excelent...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl:Script to append date and time stamp

Help with Perl script : I have a web.xml file with a line <display-name>some_text_here</display-name> Need to append the current date and time stamp to the string and save the XML file Something like <display-name>some_text_here._01_23_2014_03_56_33</display-name> -->Finally want... (5 Replies)
Discussion started by: gaurav99
5 Replies

2. Programming

CGI Perl script to execute bash script- unable to create folder

Hi I have a bash script which takes parameters sh /tmp/gdg.sh -b BASE-NAME -n 1 -s /source/data -p /dest/data/archive -m ARC gdg.sh will scan the /source/data and will move the contents to /dest/data/archive after passing through some filters. Its working superb from bash I have... (0 Replies)
Discussion started by: rakeshkumar
0 Replies

3. Solaris

System time and Cron time stamp not matching

On Solaris 10 server the system date won't match with the timestamp on files created by a cron jobs, Please help here is what i get when i check for system date infodba-ie10ux014:/tcpdv1_ie10/tcadmin/bin\n\r-> date Tue Apr 24 15:27:43 GMT 2012at same time i executed a cron job, and checked... (4 Replies)
Discussion started by: karghum
4 Replies

4. Shell Programming and Scripting

every time user input create array perl

Hi, How to create array every time user input and store user input and display all array print " Enter input " my @input = split(' ', $input) chmop($input = <STDIN>; foreach ($input) { @array= @input; } print @array"\n"; (1 Reply)
Discussion started by: guidely
1 Replies

5. Shell Programming and Scripting

How to get time duration between two human readable time stamp in Unix?

Here is two time I have: Jul 12 16:02:01 Jul 13 01:02:01 and how can I do a simple match to get difference between two time which is 09:00:00 Thanks in advance. (3 Replies)
Discussion started by: ford99
3 Replies

6. UNIX for Dummies Questions & Answers

How to get the next time stamp in perl?

Hi, I have to find the next time stamp in perl. Here is the code. @time = loaltime(time); print "\n Present time: $time:$time:$time \n"; For example if the time is: "12:55:02" after some process the time becomes 1:00:00. How do i check when it becomes 00:00 i.e from "12:55:02... (0 Replies)
Discussion started by: vanitham
0 Replies

7. Shell Programming and Scripting

how to create a logfile to track the below script output

Hi Dudes, Can you please suggest me how to create a logfile to track the below script output ? Thanks #!/bin/ksh # backup the "std" I/P file descriptor exec 5<&0 #echo "Proceed ?" while read config_line; do # backup the I/P file descriptor of "while" block exec 6<&0 # restore the... (2 Replies)
Discussion started by: shirdi
2 Replies

8. Shell Programming and Scripting

time stamp perl script error out of range 1..31

Hi, while running the perl script i am getting this error message , Day '' out of range 1..31 at rsty.sh line 44 what do iam missing in the script, any suggestion #!/usr/bin/perl use Time::Local; my $wday = $ARGV; my $month = $ARGV; # convert the month shortname into 0-11 number if... (4 Replies)
Discussion started by: saha
4 Replies

9. Shell Programming and Scripting

Perl, time stamp issue. 60th minutes

Hi Guys, Could you tell me how you can get the time stamp for 60th minutes? Currently, we name our file using time stamp upto minutes and then add seconds at the end starting from 01. And when the seconds reaches 60 we simply add 1 to the time stamp and reset the seconds to 00. But the... (3 Replies)
Discussion started by: supaLucas
3 Replies

10. UNIX for Dummies Questions & Answers

time stamp of file create

Hi, Sounds a simple request but I also need (would like) to gather the seconds too. I'm not even sure if this is held. I would think it is, somewhere??!!?! I belive that stat would/could work but I don't do C (we'll not yet). Is there any comamnd line util I can use? SunOS. Cheers... (7 Replies)
Discussion started by: nhatch
7 Replies
Login or Register to Ask a Question