LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 11-22-2003, 02:02 PM   #1
soulsniper
Member
 
Registered: Apr 2003
Distribution: Server= Fedora Core 2, Desktop= Ubuntu Hoary Preview
Posts: 41

Rep: Reputation: 15
Date in a BASH script...


Not sure if this is in the right place, but i'll go ahead....

I run a Red Hat Linux server from home and want to be able to keep weekly backups. I have an extra hard disk used for backups...

I know the command that I need to use to backup the system, the problem is I want to be able to set this up in a cron job so that it is automatically done every week. The other problem I have is that I want the filename of the backup to have the date in...

My conclusion is that I need to write a small bash script that gets the date and then runs the command to backup the system. For reference, the command I was going to use is:

sh -c RSH="/usr/bin/ssh" dump -0 -f '/backup/backup-DD-MM-YY' -u -j9 '/'

I need to get the bash script to run that command except change the DD-MM-YY to the relevant date.

I'm clueless about bash scripts so I haven't a clue.

TIA for any help recieved
 
Old 11-22-2003, 02:13 PM   #2
teval
Member
 
Registered: Jul 2003
Location: Toronto, Canada
Distribution: Gentoo
Posts: 720

Rep: Reputation: 30
Replace DD-MM-YY with:

`date +%e-%m-%y`

Including the `s
They execute what's inside and pass it's output

info date
For the maual for date
 
Old 11-22-2003, 02:18 PM   #3
soulsniper
Member
 
Registered: Apr 2003
Distribution: Server= Fedora Core 2, Desktop= Ubuntu Hoary Preview
Posts: 41

Original Poster
Rep: Reputation: 15
Thanks for the speedy reply.

However, it doesn't work. This is my script...

PHP Code:
#/bin/bash
dump --'/backup/backup-`date +%e-%m-%y`' --j9 '/' 
The script runs and starts the backup, however, the file name ends up as

backup-`date +%e-%m-%y'

Odd...


Last edited by soulsniper; 11-22-2003 at 02:26 PM.
 
Old 11-22-2003, 03:48 PM   #4
teval
Member
 
Registered: Jul 2003
Location: Toronto, Canada
Distribution: Gentoo
Posts: 720

Rep: Reputation: 30
The 's stop it from executing properly.
You can do this instead

date +%e-%m-%y|xargs -ireplacethis dump -0 -f '/backup/backup-replacethis' -u -j9 '/'

That should work
 
Old 11-22-2003, 03:53 PM   #5
soulsniper
Member
 
Registered: Apr 2003
Distribution: Server= Fedora Core 2, Desktop= Ubuntu Hoary Preview
Posts: 41

Original Poster
Rep: Reputation: 15
Thanks, that works now.
 
Old 11-22-2003, 03:54 PM   #6
teval
Member
 
Registered: Jul 2003
Location: Toronto, Canada
Distribution: Gentoo
Posts: 720

Rep: Reputation: 30
No problemo
Read the info xargs page and play around with it. It's one of the most powerful programs in my opinion.
 
Old 11-22-2003, 06:05 PM   #7
DirtDart
Member
 
Registered: Nov 2003
Distribution: Mandrake 10.1/Solaris 10 (sparc)
Posts: 96

Rep: Reputation: 16
I always prefer to set the date up as a variable, such as:


#!/bin/bash
DATE=`date +%e-%m-%y`
dump -0 -f '/backup/backup-$DATE' -u -j9 '/'
 
1 members found this post helpful.
Old 11-22-2003, 06:08 PM   #8
soulsniper
Member
 
Registered: Apr 2003
Distribution: Server= Fedora Core 2, Desktop= Ubuntu Hoary Preview
Posts: 41

Original Poster
Rep: Reputation: 15
Unfortunately I setup the cronjob to run the bash script and I instantly got an email from the Cron Daemon saying that it had failed. So instead I put the entire command "date +%e-%m-%y|xargs -ireplacethis dump -0 -f '/backup/backup-replacethis' -u -j9 '/'" as the command Cron must run.

All works fine now
 
  


Reply



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
Get file modification date/time in Bash script cmfarley19 Programming 16 04-15-2015 06:25 PM
Perl/bash - calculate date in future rose_bud4201 Programming 6 05-10-2009 05:59 AM
using bash in cron to get the date in filename rstoutmna Programming 1 12-29-2004 02:39 PM
Date calculations in BASH script Crashman Programming 4 07-03-2004 10:15 AM
Set name of tar file as date using bash otisthegbs Linux - Software 5 12-18-2003 03:34 PM

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

All times are GMT -5. The time now is 08:19 PM.

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