How To Append Date to File Name - AIX 5.3


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How To Append Date to File Name - AIX 5.3
# 1  
Old 03-29-2010
How To Append Date to File Name - AIX 5.3

Hello,

I am a novice user on an AIX 5.3 system.

I am running some scripts via crontab and redirecting the output to a file.

For example:
Code:
/home/cognos/ppdev_refresh.sh > /home/cognos/ppdev_refresh.txt

I want to append the system date to the file name so it becomes:
Code:
ppdev_refresh_20100329.txt

The process runs once a day and I want to keep all the output files and avoid having them overwritten. I have been manually renaming the file to add the suffix but that's a pain.

I have searched these forums and found some discussions of the system date but I cannot figure out how to make the syntax work.

Is what I want to do possible, and if so, what is the syntax for use in crontab?

Thanks for your help.

Maurice

Last edited by Yogesh Sawant; 03-29-2010 at 04:01 PM.. Reason: added code tags
# 2  
Old 03-29-2010
Try this:
Code:
home/cognos/ppdev_refresh.sh > /home/cognos/ppdev_refresh_$(date '+%Y%m%d').txt

# 3  
Old 03-29-2010
Franklin52,

Thank you for your prompt reply.

I tried this at the command line and it worked. I will use it in crontab next.

I appreciate your help.

Maurice
# 4  
Old 03-31-2010
Hello again,

The solution above works exactly as I wanted in the command prompt, but the same syntax gives different results when run from crontab.

When I add this line to crontab:

31 11 * * * /home/cognos/check_disk_free.sh > /home/cognos/check_disk_free_$(date '+%Y%m%d').txt


This is a file name generated by crontab:

check_disk_free_Wed Mar 31 11:31:00 EDT 2010

(no extension applied)

What am I doing wrong?

How do I specify the date format in crontab so the suffix becomes _20100331.txt

Thanks again for your help
# 5  
Old 03-31-2010
Strange, try to escape the % sign and don't use quotes:
Code:
/home/cognos/check_disk_free_$(date +\%Y\%m\%d).txt

# 6  
Old 03-31-2010
If cron's using an incredibly old shell, you might try backticks, "filename_`command`" instead of "filename_$(command)"
# 7  
Old 03-31-2010
Franklin52,

Thanks, this syntax works in crontab. The file name produced is now:

check_disk_free_20100331.txt

Just what I wanted.

I appreciate your help. This is an excellent forum and I am glad I found it.

Maurice
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Append date to sql*plus spool (log) file in shell script

SQL*Plus version : 11.2.0.4 OS : Oracle Linux 6.5 SQL*Plus is a client application to connect to oracle database. The log file for this tool is generated via spool command as shown below. I am trying to append date ( $dateString ) to spool file as shown below. $ cat test2.sh #!/bin/bash... (4 Replies)
Discussion started by: kraljic
4 Replies

2. Shell Programming and Scripting

Append orginal file date to end of file

Trying to process 1000 or so files. Take original date and append to end of file. Like so: tstpls42.bas tstpls42.bas.Sep-11--2011 Been working along these lines: date=`ll tstpls42.bas |cut -c 46-57 |sed -e 's/]/\-/g' | grep -v '^$'` for i in *.bas ; do j=`ll $i /hpdump/b1 | awk... (1 Reply)
Discussion started by: joeadmin
1 Replies

3. Shell Programming and Scripting

Want it to read the file name and then append date stamp at the end of file?

I was thinking something like for i in `find . -name "*.log.Z"`; do mv $i name.log.Z or something like that? (3 Replies)
Discussion started by: xgringo
3 Replies

4. Shell Programming and Scripting

Delete log files content older than 30 days and append the lastest date log file date

To delete log files content older than 30 days and append the lastest date log file date in the respective logs I want to write a shell script that deletes all log files content older than 30 days and append the lastest log file date in the respective logs This is my script cd... (2 Replies)
Discussion started by: sreekumarhari
2 Replies

5. UNIX for Dummies Questions & Answers

append file name with date

Hi guys, I created a very basic script that moves a specified file to a directory that I have set using the mv command. What I would like to do is append the file name with the date and time. So if I was to use the script to move a file called abc.txt, the script should rename the file... (1 Reply)
Discussion started by: jjc
1 Replies

6. Solaris

Find a file and xarg mv to append date to file

Hello All, What I would like to do is search for a file and then run a mv command to rename the file to have todays date appended to it. The find when I run it finds eight or so files and I would like to append a date stamp to each file. If possible using one line command would be great. Can... (6 Replies)
Discussion started by: jacktravine
6 Replies

7. Solaris

gzip a file and append creation date stamp to file

I want to gzip a file and append the creation date to the end of the file. How can I accomplish this task. Basically they are log files which need a creation date stamp appended to make sure they do not overwrite other log files. -jack (3 Replies)
Discussion started by: jacktravine
3 Replies

8. Shell Programming and Scripting

append date to file

Hi I need to append date to filename.Wrote script to get the date from table ,take this date filed and append to my i/p file when call the below script.Any help should be appreciated . Exampel If call the below script a4.sh filename o/p should be filename.2008-02-29 .... (6 Replies)
Discussion started by: mohan705
6 Replies

9. Shell Programming and Scripting

Append date to a file from CRON

Hi, I am trying to append date in DAY_Mon_dd_yyyy at the end of a filename from cron. Cron entry looks as below. (script to execute) > test_file_`date +"a_%b_%d_%Y"` File name created after executing the job is test_file_ I am expecting the filename to be something like ... (8 Replies)
Discussion started by: dncs
8 Replies

10. Shell Programming and Scripting

Need a script to Append date to generated .txt file

Hi, Can anyone plz share their experience with - Building shell script to append the file with date in following format- Filename_MMDDYYYY.txt Thanks in advance (2 Replies)
Discussion started by: prince_of_focus
2 Replies
Login or Register to Ask a Question