[lug] I need help from a bash scripting guru

Paul E Condon pecondon at mesanetworks.net
Sun Jan 6 17:17:14 MST 2008


I'm working on a file backup script that has a feature
of my own design. I have written a script that uses 

  cp -au --backup=t <srcdirpath> <backupdirpath>

for the bulk of the work. With these options 
(particularly --backup=t) all old versions of files that
change are preserved in the backup.

I like this for grabbing clean copies of things that I
have accidentally clobbered. But I wanted more ---

I also wrote a few lines that check if a file has been
deleted from the source and writes, for such file, a
record into the backup giving the time/date when a
backup process first noticed that the file was missing.

To do this, I produce two files of the names of files
in both the source using

find . -type f | sort > <filenamelist>

to create a sorted list of file names for source and 
backup and then use 

join -j 1 -v 2 <sourcelist> <backuplist> >missinglist

( the -v 2 writes records from the second input that don't 
join to any record from the first input)

This works fine so long as there are no spaces in any of the file
names.  Now I want to make it work for spaces and general garbage in
the file name. I have almost a solution: with -t \` added to the join
command, the accent-grave, or 'back-quote' character becomes the field
delimiter in join. This works fine so long as there are no back-quotes
in any of the file names, and there aren't any --- so far. But I'd
like a more bullet proof solution.

Is there some way to tell join to use, for example, the line-feed
character as field delimiter? Or some other character which should
never appear in proper file names under UNIX, or Mac OSX, as
implemented by netatalk, or Windows names as handled by Samba? Put
another way - Is there one character that never appears in file names
of all these OSs, and can be introduced as the field delimiter into
GNU join?

TIA
--
Paul E Condon           
pecondon at mesanetworks.net



More information about the LUG mailing list