[mdlug] Bashing bash with a pipe

Jeff Hanson jhansonxi at gmail.com
Sat Sep 10 15:33:04 EDT 2011


Script is here:  http://www.mediafire.com/?6sv5ew4w9fjkuc7

I'm having trouble with a bash script.  I was looking for a way to
obtain all of the Ubuntu MD5/SHA1/SHA256 checksums from their CD image
server, verify them with gpg, then concatenate them all into a master
file I can grep against.  Any that fail are concatenated into a reject
list.  I also wanted a log of the operations in case of problems.  The
script achieves this but there is a problem.  The structure is:

get-ubuntu-checksums <target_dir> <URL>
----------------------------
(variables and exports)

f_gpgcheck () {
echo filename >> logfile
gpg --verify ... 2>> logfile
if good then
 echo filename >> master_file
 cat filename >> master_file
else
 echo filename >> master_file_rejects
 cat filename >> master_file_rejects
fi
}

wget <checksums> --recursive ...--directory-prefix="$target_dir" (URL)
 >> logfile 2>&1

find -delete (empty files and dirs) >> logfile 2>&1

export -f f_gpgcheck

find "$target_dir" -type f ! -iname '*.gpg' -exec bash -c 'f_gpgcheck {}' \;

exit
---------------------------

This seems to work except for one problem - the contents of the log
file end up mixed in with the reject file.  It seems to be a pipe
collision between the subshell and the parent stdout but I don't know
how to fix it.



More information about the mdlug mailing list