Computing.Net > Forums > Linux > add timestamp to file in linux

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

add timestamp to file in linux

Reply to Message Icon

Name: nnyantengwar
Date: April 28, 2004 at 16:03:44 Pacific
OS: RHEL 3
CPU/Ram: P4 Xeon 4gb
Comment:

Hello,
I am currently running a shell script on crontab that uses mysqldump to backup my db on a daily basis then FTPs the file to another server.

I have the script working fine but I would like to keep a "history" of the db by attaching the systems current date to the filename (EX sqlbackup_04282004.tar.gz sqlbackup_04292004 etc...)

Heres what I have working so far:

#! /bin/bash
/usr/local/mysql/bin/mysqldump --opt -u username -pPASSWORD dbname > /home/dir1/dir2/dir3/backup.sql
cd /home/dir1/dir2/dir3
tar -czvf sqlbackup.tar.gz /home/dir1/dir2/dir3/backup.sql
lftp <<EOF
open ftpserver
user username password
pwd
ls
put sqlbackup.tar.gz
bye
EOF



Sponsored Link
Ads by Google

Response Number 1
Name: Jake
Date: April 28, 2004 at 17:21:04 Pacific
Reply:

Use "sqlbackup_`date +%m%d%Y`.tar.gz" for the filename. Note that those are backticks, not apostrophes. Read the man page for date if you want a different format.


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Linux Forum Home


Sponsored links

Ads by Google


Results for: add timestamp to file in linux

How to OPEN+RUN .exe files in Linux www.computing.net/answers/linux/how-to-openrun-exe-files-in-linux/16329.html

FAST-HOW-TO XDMCP in Linux www.computing.net/answers/linux/fasthowto-xdmcp-in-linux/21099.html

How to read msword file in linux or unix www.computing.net/answers/linux/how-to-read-msword-file-in-linux-or-unix/11133.html