LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Date in a BASH script... (https://www.linuxquestions.org/questions/linux-software-2/date-in-a-bash-script-118927/)

soulsniper 11-22-2003 02:02 PM

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

teval 11-22-2003 02:13 PM

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

soulsniper 11-22-2003 02:18 PM

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...


teval 11-22-2003 03:48 PM

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

soulsniper 11-22-2003 03:53 PM

Thanks, that works now.

teval 11-22-2003 03:54 PM

No problemo
Read the info xargs page and play around with it. It's one of the most powerful programs in my opinion.

DirtDart 11-22-2003 06:05 PM

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 '/'

soulsniper 11-22-2003 06:08 PM

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 :)


All times are GMT -5. The time now is 11:18 AM.