script problem
- From: "Steven Buehler" <steve@xxxxxxxxxxxx>
- Date: Thu, 13 Dec 2007 10:56:34 -0600
I have a backup script that I wrote. In it I have a variable that
has listings of directories to back up. Because of some of the sizes of the
directories, and for other reasons, they now want me to break them where I
back them up into multiple files with the name of the directory instead of
all in one file. It would be simple except that I can't find how to get
just the final directory name for each directory.
Example:
DIRSTOBACKUP= "/usr/local/bin
/etc
/home/steve
/usr/local/src"
I can read thru each line of the variable, but unless I use the "split"
function and assign each item in the split, I can't get the last name of the
directory. How can this be accomplished? I guess it might be easier to
find a way to just chop off the first "/" and then replace the rest with "_"
and use that as the backup file name. That way they can also look at the
file name and see what directory it came from if I am able to replace the
"/" characters. But alas, I am not that great at the regular expression
replacement in a string either. I have tried:
DIRSTOBACKUP= "/usr/local/bin
/etc
/home/steve
/usr/local/src"
for name in ${DIRSTOBACKUP[@]}
do
NEWNAME=sed "s/\//_/g" < $name
echo $NEWNAME
done
But that doesn't seem to work. Any ideas?
Thanks
Steve
--
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list
- Follow-Ups:
- Re: script problem
- From: Jerry Queirolo
- RE: script problem
- From: Kristoffer K***
- Re: script problem
- Prev by Date: Re: queer dns access problem
- Next by Date: RE: script problem
- Previous by thread: Problems using xen 3.1 | bridged network
- Next by thread: RE: script problem
- Index(es):