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 |
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 |
Thanks for the speedy reply.
However, it doesn't work. This is my script... PHP Code:
backup-`date +%e-%m-%y' Odd... |
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 |
Thanks, that works now.
|
No problemo
Read the info xargs page and play around with it. It's one of the most powerful programs in my opinion. |
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 '/' |
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. |