to name a file after the date

Posted on 2000-01-22
Medium Priority
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?
Question by:toulon
  • 2
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");

Expert Comment

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

Accepted Solution

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.

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

system("ls > $date_string");


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