how to display date with filename??


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how to display date with filename??
# 1  
Old 06-30-2010
Question how to display date with filename??

Hi i am currently using below command in shell script and calling it from cron job.
This is to take daily backup with the date as suffix to the file.When i try i unable to get the date suffixed to the backup file.

Please help me as to wt's wrong in this or how to get the date added to the backup file?Smilie and also how to redirect output to a file and errors to another. i tried using double codes, but still not working out..

The below command is in shell script:
pg_dump -h ipaddress -p 5432 -U postgres -F c -v -f '/apps/cmplus/backup/`date +P4CMPlus_int_67.%m.%d.%Y.backup`' "P4CMPlus_int"

the output iam getting is :

`date +P4CMPlus_int_67.%m.%d.%Y.backup`

the output should be:
P4CMPlus_int_67.06.30.2010.backup SmilieSmilie
# 2  
Old 06-30-2010
You have not used the date command properly, below is the correct one.

P4CMPlus_int_67.06.30.2010.backup

P4CMPlus_int_67.<--------->.backup

<partoffilename><date><partoffilename>

P4CMPlus_int_67.`date +'%d%m%Y'`.backup

- For redirecting the output and erros to files, in your cron entry add the below at the last
> <output filename> 2><error filename>
# 3  
Old 06-30-2010
How does this work:
Code:
pg_dump -h ipaddress -p 5432 -U postgres -F c -v -f "/apps/cmplus/backup/`date +P4CMPlus_int_67.%m.%d.%Y.backup` P4CMPlus_int"

# 4  
Old 06-30-2010
Further to vishalaswani.

You have the wrong sort of quotes. Anything between single quotes will not be expanded. Use double quotes.

Just seen Scrutinizer's post which tackles both issues.
# 5  
Old 07-01-2010
Question

thanks methyl,Scrutinizer and vishalaswani for the inputs and help.

I am getting the date suffixed to file name, but when i take the backup dump of database(eg:P4CMPlus_int postgres) i am unable to take with the below added quotes "" modification.Smilie

pg_dump -h ipaddress -p 5432 -U postgres -F c -v -f "/apps/cmplus/backup/`date +P4CMPlus_int_67.%m.%d.%Y.backup` P4CMPlus_int"

also tried with substituting below quotes
"/apps/cmplus/backup/daily_backup`date +P4CMPlus_int_67.%m.%d.%Y.backup`" "P4CMPlus_int"

output:
P4CMPlus_int_67.07.01.2010.backup P4CMPlus_int

Any help or clues to take the dump of this DB.
# 6  
Old 07-01-2010
Did you try this subtle variation.

Code:
pg_dump -h ipaddress -p 5432 -U postgres -F c -v -f "/apps/cmplus/backup/`date +P4CMPlus_int_67.%m.%d.%Y.backup`" P4CMPlus_int


Which is directly comparable to the line in your parallel post.
Code:
/usr/PostgreSQL/8.3/bin/pg_dump -h <ip addr> -p 5432 -U postgres -F c -v -f '/apps/cmplus/backup/daily_backup/P4CMPlus_ZDC.backup' "P4CMPlus_ZDC"

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to change existing date to current date in a filename?

Suppose i have a list of files in a directory as mentioned below 1. Shankar_04152019_ny.txt 2. Gopi_shan_03122019_mi.txt 3. Siva_mourya_02242019_nd.txt .. . . . . 1000 . Jiva_surya_02282019_nd.txt query : At one shot i want to modify the above all filenames present in one path with... (4 Replies)
Discussion started by: Shankar455
4 Replies

2. Shell Programming and Scripting

UNIX script to display the filename

Hi All How to answer the below interview question.. With a path and filename of "/mydir1/mydir2/mydir3/myfilenane.dat" write a UNIX script to display the filename (2 Replies)
Discussion started by: shumail
2 Replies

3. Shell Programming and Scripting

How to append date to filename, but base it on yesterday's date?

Hello, I'd like to write a monthly archive script that archives some logs. But I'd like to do it based on yesterday's date. In other words, I'd like to schedule the script to run on the 1st day of each month, but have the archive filename include the previous month instead. Here's what I... (5 Replies)
Discussion started by: nbsparks
5 Replies

4. Shell Programming and Scripting

Display the Filename and Size of a File

Hello, all! Working in a Bourne shell. What command would list the filename and size of a file if the size of the file had to be bigger than $a and smaller than $b? Output (if $a is 10 bytes and $b is 50 bytes):test1.txt 15 test2.txt 30 test3.txt 50 Thanks, Ann :p (3 Replies)
Discussion started by: LowlyIntern
3 Replies

5. Shell Programming and Scripting

How to display a date, 30 days from the current date?

Well guys, I know the right syntax for displaying the current date is $(date). However, I am planning to send emails to some customers which displays their subscription date, and then the expiry. The expiry being 30 days from the current date. What would the right syntax be? (6 Replies)
Discussion started by: xxxx
6 Replies

6. Shell Programming and Scripting

Get the oldest date based on date in the filename

I am using ksh93 on Solaris. Ok, this may seem like a simple request at first. I have a directory that contains sets of files with a YYYYMMDD component to the name, along with other files of different filespecs. something like this: 20110501_1.dat 20110501_2.dat 20110501_3.dat... (2 Replies)
Discussion started by: gary_w
2 Replies

7. Shell Programming and Scripting

How to grep for message and if found display filename?

Hi i'm new to the forum and was hoping someone could help me with the following query. I do alot of testing and have hundreds of log files output. I have a script (someone else wrote) which finds all the passed and failed logs and puts a number in a column onto a webpage: e.g: Pass ... (4 Replies)
Discussion started by: defamer
4 Replies

8. UNIX for Dummies Questions & Answers

Display last 8 character of filename

I would like to display the last 8 characters of the filenames for filenames of different lengths. I can delete the last 8 characters with sed but dont know how to only show the last 8 characters. The filenames are something like; afxH340800340000 afxH30800340021 afxR3080034002122 I... (3 Replies)
Discussion started by: Beanz
3 Replies

9. Shell Programming and Scripting

display filename with date

Hi buddies, I have a doubt. I want to display filename with date in the following format.Is there any way to do this. Kindly give me the solution. I want to display the result in the following manner. test1.txt 03/28/2008 testlog.log 02/20/2008 Please let me know one solution how to do... (1 Reply)
Discussion started by: pstanand
1 Replies

10. UNIX for Dummies Questions & Answers

Display filename and wc stats

I'm just learning UNIX and I'm trying to do the following: Write a script called details.bash that, for each file in the working directory, prints the filename, the # of lines, and the # of words to to some output file, like this: filename1 73 431 filename2 5 21 It's probably a stupid... (1 Reply)
Discussion started by: asianmike
1 Replies
Login or Register to Ask a Question