View Single Post
  #1  
Old 5th July 2012, 20:50
Diggy Diggy is offline
Junior Member
 
Join Date: Aug 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default [SOLVED] Bash script help

Hi, all.

I'm in the midst of creating a bash script to archive certain directories to a NAS device. I'm not a great script writer, and would appreciate your help. Here's what I have, so far:

#!/bin/bash
FILENAME="backup"`date -d "last month" +%Y%m`".txt"
touch $FILENAME
touch --date "2012-06-01" /tmp/start
touch --date "2012-06-30" /tmp/end
find /data/nightly_data_backup -type d -newer /tmp/start -not -newer /tmp/end -print | sort > $FILENAME
mount -t nfs netdisk219:/mnt//vol001/volume02/Archive/Database /backup
tar -czvf /backup/2012_04.tar.gz --files-from $FILENAME

How can I use variables to substitute in the dates in the commands:

touch --date "2012-06-01" /tmp/start
touch --date "2012-06-30" /tmp/end

The dates should be the begin and end dates of the preceding month from the date I run the script, and:

tar -czvf /backup/2012_04.tar.gz --files-from $FILENAME

The name of the tar file should also be the preceding month, in the format shown above.

Many thanks.

Diggy

Last edited by Diggy; 6th July 2012 at 20:22.
Reply With Quote
Sponsored Links