Use temp files in current directory, not /tmp, to reduce security risk
while running this script.
This commit is contained in:
parent
fb22b32095
commit
a171fc1a4f
@ -10,27 +10,32 @@
|
|||||||
# Caution: you may need to use GNU awk.
|
# Caution: you may need to use GNU awk.
|
||||||
AWK=${AWK:-awk}
|
AWK=${AWK:-awk}
|
||||||
|
|
||||||
trap "rm -f /tmp/$$ /tmp/$$a /tmp/$$b" 0 1 2 3 15
|
INPUTFILE="tmp$$a"
|
||||||
|
DUPSFILE="tmp$$b"
|
||||||
|
NONDUPSFILE="tmp$$c"
|
||||||
|
rm -f $INPUTFILE $DUPSFILE $NONDUPSFILE
|
||||||
|
|
||||||
|
trap "rm -f $INPUTFILE $DUPSFILE $NONDUPSFILE" 0 1 2 3 15
|
||||||
|
|
||||||
# Read input
|
# Read input
|
||||||
cat "$@" >/tmp/$$
|
cat "$@" >$INPUTFILE
|
||||||
|
|
||||||
# Look for fields with multiple references.
|
# Look for fields with multiple references.
|
||||||
cat /tmp/$$ | cut -d' ' -f2 | sort | uniq -d >/tmp/$$a
|
cat $INPUTFILE | cut -d' ' -f2 | sort | uniq -d >$DUPSFILE
|
||||||
if [ -s /tmp/$$a ] ; then
|
if [ -s $DUPSFILE ] ; then
|
||||||
echo "Ignoring these fields that link to multiple tables:" 1>&2
|
echo "Ignoring these fields that link to multiple tables:" 1>&2
|
||||||
cat /tmp/$$a 1>&2
|
cat $DUPSFILE 1>&2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get the non-multiply-referenced fields.
|
# Get the non-multiply-referenced fields.
|
||||||
cat /tmp/$$ | while read LINE
|
cat $INPUTFILE | while read LINE
|
||||||
do
|
do
|
||||||
set -- $LINE
|
set -- $LINE
|
||||||
grep "^$2\$" /tmp/$$a >/dev/null 2>&1 || echo $LINE
|
grep "^$2\$" $DUPSFILE >/dev/null 2>&1 || echo $LINE
|
||||||
done >/tmp/$$b
|
done >$NONDUPSFILE
|
||||||
|
|
||||||
# Generate the output.
|
# Generate the output.
|
||||||
cat /tmp/$$b |
|
cat $NONDUPSFILE |
|
||||||
$AWK -F'[ \.]' '\
|
$AWK -F'[ \.]' '\
|
||||||
BEGIN \
|
BEGIN \
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user