On 6 Jan, Simon Bryan wrote:
> Hi all,
> I am moving my users home directoires from one server to another and in
> the process standardising usernames such that about 300 need changing.
> Once I hav copied over the directories (cp -a) I will then need to rename
> some of the directories. I have a csv file with the format
> "oldname,newname" and a script to read it:
>
> #!/bin/bash
> while read name1 name2; do
> mv $name1 $name2
> # done < /home/OLMC/snap/rename.txt
Um, apart from the already-mentioned problems, I see no error checking
there at all. What do you do if the disc fills, or if names clash?
I assume names have no white space. But there are probably dozens of
things that could go wrong.
IFS=",$IFS"
while read name1 name2
do
[ -f "$name2" ] && echo "$name2 is a file!" && exit 1
[ -d "$name2" ] && echo "$name2 already taken!" && exit 1
mv "$name1" "$name2" || echo "Bailing out at $name1 -> $name2" && exit 1
done < /home/OLMC/snap/rename.txt
But there are probably lots of other things that could go wrong. I
hope you have complete and trustworthy backups?
luke
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html