LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Set name of tar file as date using bash (https://www.linuxquestions.org/questions/linux-software-2/set-name-of-tar-file-as-date-using-bash-126932/)

otisthegbs 12-18-2003 10:23 AM

Set name of tar file as date using bash
 
Hey everybody. I have a bash question that is totally out of my league. What I would like to do is make a bash script that backups a folder to a tar.gz file on my backup drive. But I want the name of the file to be the date it was archived on. Heres what I have so far

#!/bin/sh
mount /dev/sda1 /usr/backup/
tar -cvzf /usr/backup/(date of compress variable).tar.gz /var/www/html/
umount /dev/sda1
#thank you and have a nice day

If anyone knows if there is a simple way to call the date down from bash I would love to know, and if its not so simple, then maybe some guidance.

Thx

jkobrien 12-18-2003 10:41 AM

Did you try 'date'?

It probably won't return the format you want, but check the manpages, or use sed to fix that.

John

ALF 12-18-2003 10:58 AM

Date
 
Hi,

I'm UNIX expert, but I think this should work :

#!/bin/sh
NOWDATE=`date +%d%m%y`
mount /dev/sda1 /usr/backup/
tar -cvzf /usr/backup/$NOWDATE.tar.gz /var/www/html/
umount /dev/sda1
#thank you and have a nice day


the date format is going to look like that : 181203 (for today's date), if you need different format (for example to add the time %H:%M:%S).

Alf

ALF 12-18-2003 11:00 AM

NOT UNIX expert
 
Sorry, I meant in my last posting to say: I'm NOT a UNIX expert.

Alf

jkobrien 12-18-2003 11:07 AM

Heh-heh.

You can always just edit stuff like that. If you're quick, chances are that no-one will have noticed.

John

otisthegbs 12-18-2003 03:34 PM

thanx
 
DUDE! it worked, thx alot

solution = `date +%m%d%y`


All times are GMT -5. The time now is 05:51 PM.