Forum Moderators: bakedjake
MattyMoose gave me some great advice a while back when I was trying to automate a backup process, the result being the following command:
find ./ -name "*.txt" -print ¦ tar czf archive/db_022006.tar.gz -T - && find ./ -name "*.txt" -exec rm {} \;
Well now I want to take it a bit further so that the tar will be created and named according to the current date. So, I got the current date using:
date '+%d%m%Y'
But how can I put this into the backup command above?
I tried:
find ./ -name "*.txt" -print ¦ tar czf date '+archive/db_%d%m%Y.tar.gz' -T - && find ./ -name "*.txt" -exec rm {} \;
But unfortunately that didn't work. Anyone got a sokution they could share?
Many thanks
I had tried a couple of bracket combinations, didn't know about the $ in front though - is there a good reference for this sort of thing somewhere? Coming from a Windows environment its quite a steep learning curve, that said I'm already finding you can do so much with just a single line command.
Many thanks
Same idea as what coopster said, just I prefer to be able to reuse the date variable throughout my script, so I usually define something like this:
#!/bin/tcsh
DATE=`date '+%d%m%Y'`
... do stuff ...
find ./ -name "*.txt" -print ¦ tar czf date '+archive/db_${DATE}.tar.gz' -T - && find ./ -name "*.txt" -exec rm {} \;
Then that way you can re-use the date variable.
I can't seem to find the bookmark I had that I used as reference for shell scripting, but give this a try, or search around a bit, find a format that you like. :) [freeos.com...]
Cheers,
MM