[ Please press <RETURN> every 70 or so chars. Thanks. ]
On Mon, Jan 29, 2001 at 09:38:48PM -0600, Jonathan Wilson <[EMAIL PROTECTED]> wrote:
| I just wrote a bash script for making manual backups easier (I do them manuall
| y when I'm about to edit something major) it basically makes a new directory in
| /backup/ who's name is equal to today's date, then recursively copies certain di
| rs I want backed up.
| The problem is, on some projects I like to do the manual backup each time I ge
| t to a stable point before making the next few edits. What I'm wanting is for th
| e script to check and see if a directory with today's date already exists. If it
| does I want it to append the hour as well as the date. Then if there's already
| on with the same hour it should append the minute.
| Another option would be for it to add something like _1 to the end and increme
| nt _1 by one digit each time (_2, _3, _4....) but I like the day, then hour, the
| n minute better. I guess we could add seconds for amusement's sake.
My personal habit is to try for the date (yyyy-mm-dd) and if that fails
go straight for yyyy-mm-dd-hh:mm:ss outright. None of these compromises!
They are for The Weak!
As Matthew Melvin remarked, you want the -d test.
Or you can do this:
day=`date '+%Y-%m-%d'`
now=`date '+%Y-%m-%d-%H:%M:%S'`
mkdir "$day" || mkdir "$now" || exit 1
Those are short circuiting OR operators, this make the first choice or
if not then make the second or if not then abort.
Of course, you want to know which dir you ended up with, so maybe:
day=`date '+%Y-%m-%d'`
now=`date '+%Y-%m-%d-%H:%M:%S'`
{ mkdir "$day" && dir=$day; } \
|| { mkdir "$now" && dir=$now; } \
|| exit 1
cp stuff into $dir
Cheers,
--
Cameron Simpson, DoD#743 [EMAIL PROTECTED] http://www.zip.com.au/~cs/
In the desert, you can remember your name,
'cause there ain't no one for to give you no pain. - America
_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list