[plug] Ambiguous redirection error

Anthony J. Breeds-Taurima tony at cantech.net.au
Sat May 11 10:08:36 WST 2002


On Sat, 11 May 2002, Richard wrote:

> I am currently trying to write a script(s) that will backup certain personal 
> files on a regular basis. My email is one of the things I would like to 
> backup and, using kmail, it resides in a single dir, Mail, in mbox format. I 
> have been trying to work out a command to append all files in the Mail dir to 
> their name sake in a separate backup dir, which would then be re-archived. I 
> have been trying to redirect the output of the cat command to the backup 
> files and using the * to perform the action on all files in the dir, but I 
> keep getting the error message 'ambiguous redirection'. I could explicitly 
> name all of my mail files/folders in the script but would like to avoid 
> having to update the script every time a new folder is added in kmail. Could 
> anyone suggest a command-line string that would have the desired effect? Or a 
> better way of regularly archiving my mail (if I'm in danger of re-inventing 
> the wheel :) Thanks.

If I understand you you want to do something like:
---
cd ~/path/mail
for i in * ; do
	cat $i >> ~/path/backup/$i
done
---

That will for every file in ~/path/mail append it's contents to a file witht
the same name in ~/path/backup.

As others have suggested tar is a reasonable way to do a backup.

You could do something like:


------
DATE_STAMP=$(date +"%Y%m%d")

for dir in /path1 /path2 /path3 ; do
	DIR_NAME=$(/bin/echo "$dir" | sed -e 's/\//-/')

	if [ -z "$1" ] ; then
		FIND_ARGS="-newer $dir/.incr"
	else
		FIND_ARGS=""
	fi

	cd "$dir"
	find . $FIND_ARGS -print0 | cpio -i0mp | \
		bzip2 -9 > /path/to/backup/$DIR_NAME_$DATE_STAMP_tbz

	touch "$dir/.incr"
done
------

If you run that script with no arguments is will only backup files that
have changed since your last backup.  If you run it with any arg it will
backup all files.  I haven't tested the script at all so you'll want to 
check the command arguments to cpio find etc etc with the man pages.

cpio has an "exclude" option so if you have _very_ large files in your
home directory then you can make an exclude file somewhere to make sure
you don't backup that 1.9Gb VMware machine :)
> 


Yours Tony.

/*
 * "The significant problems we face cannot be solved at the 
 * same level of thinking we were at when we created them."
 * --Albert Einstein
 */



More information about the plug mailing list