?
Solved

to name a file after the date

Posted on 2000-01-22
3
Medium Priority
?
198 Views
Last Modified: 2010-03-05
in a cron script I want to name an output file after the date of the day in command line like :
ls > 'fileoftheday'.log

Could you tell me how I do that?
Thx.
0
Comment
Question by:toulon
  • 2
3 Comments
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 2378452
This will create files with a name of YYYYMMDD.log, which is best for sorting by date order.

($day,$month,$year) = (localtime)[3..5];
$date_string = sprintf("%04d%02d%02d%s", $year+1900, $month+1, $day,'.log');

system("ls > $date_string");
0
 
LVL 2

Expert Comment

by:cadabra
ID: 2379718
ls > `date '+%d%m%Y'`.log
0
 
LVL 19

Accepted Solution

by:
Kim Ryan earned 100 total points
ID: 2382696
If you place a call to this this perl script in the  crontab it should give you what you want.

#!/usr/bin/perl
($day,$month,$year) = (localtime)[3..5];
$date_string = sprintf("%04d%02d%02d%s", $year+1900, $month+1, $day,'.log');

system("ls > $date_string");


0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Article by: Tammy
MySQLTuner is a script written in Perl that allows you to review a MySQL installation quickly and make adjustments to increase performance and stability. The current configuration variables and status data is retrieved and presented in a brief forma…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question