[GRLUG] file backup script
Michael Mol
mikemol at gmail.com
Tue Jul 17 19:28:02 EDT 2007
On 7/17/07, Bill Pribble <Bill.Pribble at haworth.com> wrote:
> Here is a shot at it.
>
> for i in $(cat file.txt)
> do
>
> FILE=$(find /dir/to/start/search -name ${i})
>
> if [ ${FILE} ] #if FILE is not empty
> then
> cp -p ${FILE} /local/dir #copy file from remote dir to local dir
> fi
>
> done
>
> Thanks
Ow! You're running a find operation for each file.
Here's a more efficient script: (Untested...I don't have decent access
to a Linux box at the moment.)
find /dir/to/start/search >/tmp/mytmpindex$$
grep -f file.txt /tmp/mytmpfile > /tmp/mytmpfoundfiles$$
for i in $(cat /tmp/mytmpfoundfiles$$)
do
cp -p ${FILE} /local/dir #copy file from remote dir to local dir
done
rm /tmp/mytmp*$$
...
It would be even better if we could guarantee that the locate db was
up-to-date and would return all relevant results.
--
:wq
More information about the grlug
mailing list