you could try some "autoincrement" script 

#!/bin/bash
# handles sub-directories in /backup, name format something like "sub_###"
with ### being a serial number
# get the last one
last=$(ls -1 /backup/sub* | sed -e s/^.*_// | sort -nr | head -n 1)
new=$(($last + 1))
mkdir /backup/sub_$new
cp -a /etc /backup/sub_$new



A 21:38 29/01/2001 -0600, vous avez écrit :
>Howdy,
>
>I just wrote a bash script for making manual backups easier (I do them
manually 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 dirs I want backed up.
>
>The problem is, on some projects I like to do the manual backup each time
I get to a stable point before making the next few edits. What I'm wanting
is for the 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
increment _1 by one digit each time (_2, _3, _4....) but I like the day,
then hour, then minute better. I guess we could add seconds for amusement's
sake.
>
>Anyway, I'm sure I could figure out how to do an if...else loop, I've seen
examples, but in bash I've never seen an example of checking for the
existence of a file or dir. Can anyone show me how to do that?
>
>Here's what I have:
>
>#!/bin/bash
>#
>#First find out what today is
>#
>#
>#oldformat: today=$(date +%Y_%m_%d)
>#
>#new format:
>today=$(date +%m-%d-%Y)
>echo "Today is" $today
>mkdir /backup/$today && echo "backup dir $today created"
>cp -a /etc /backup/$today && echo "etc copied"
>echo
>echo "Done"
>
>
>Thanks in advance...
>
>----------------------------------------------------
>Jonathan Wilson
>System Administrator
>
>Cedar Creek Software
>http://www.cedarcreeksoftware.com
>
>Central Texas IT
>http://www.centraltexasit.com
>
>
>
>_______________________________________________
>Redhat-list mailing list
>[EMAIL PROTECTED]
>https://listman.redhat.com/mailman/listinfo/redhat-list
>
>
                        - * - * - * - * - * - * -
Mes idees n'engagent que moi (vieux proverbe du Net)

Thierry ITTY
eMail: [EMAIL PROTECTED]                FRANCE



_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to