LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-18-2003, 10:23 AM   #1
otisthegbs
Member
 
Registered: May 2003
Location: Vancouver
Distribution: RH9
Posts: 100

Rep: Reputation: 15
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
 
Old 12-18-2003, 10:41 AM   #2
jkobrien
Member
 
Registered: Jun 2003
Location: Dublin, Ireland
Distribution: Slackware, LFS, Ubuntu, RedHat, Slamd64
Posts: 507

Rep: Reputation: 30
Did you try 'date'?

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

John
 
Old 12-18-2003, 10:58 AM   #3
ALF
Member
 
Registered: Oct 2002
Posts: 32

Rep: Reputation: 15
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

Last edited by ALF; 12-18-2003 at 12:01 PM.
 
Old 12-18-2003, 11:00 AM   #4
ALF
Member
 
Registered: Oct 2002
Posts: 32

Rep: Reputation: 15
NOT UNIX expert

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

Alf
 
Old 12-18-2003, 11:07 AM   #5
jkobrien
Member
 
Registered: Jun 2003
Location: Dublin, Ireland
Distribution: Slackware, LFS, Ubuntu, RedHat, Slamd64
Posts: 507

Rep: Reputation: 30
Heh-heh.

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

John
 
Old 12-18-2003, 03:34 PM   #6
otisthegbs
Member
 
Registered: May 2003
Location: Vancouver
Distribution: RH9
Posts: 100

Original Poster
Rep: Reputation: 15
thanx

DUDE! it worked, thx alot

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how can i decompress this tar.tar file? hmmm sounds new.. tar.tar.. help ;) kublador Linux - Software 14 10-25-2016 02:48 AM
Get file modification date/time in Bash script cmfarley19 Programming 16 04-15-2015 06:25 PM
gave wrong syntax for tar as tar -cvzf file file.tgz how to recover the file gautham Linux - General 4 04-13-2005 03:15 AM
howto create a file based on date in bash rohan208 Linux - Newbie 2 05-07-2004 03:54 PM
tar file name with system date mnauta Linux - General 4 12-19-2003 04:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration