mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-11 21:51:21 +00:00
Don't use random file in mk-mext. Quote file names. Remove tmp dir.
This commit is contained in:
34
bin/pt-mext
34
bin/pt-mext
@@ -26,9 +26,6 @@ fi
|
|||||||
# See https://launchpad.net/percona-toolkit for more information.
|
# See https://launchpad.net/percona-toolkit for more information.
|
||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
|
|
||||||
# pt-mext isn't ready for this yet
|
|
||||||
#set -u
|
|
||||||
|
|
||||||
TMPDIR=""
|
TMPDIR=""
|
||||||
|
|
||||||
mk_tmpdir() {
|
mk_tmpdir() {
|
||||||
@@ -60,10 +57,9 @@ rm_tmpdir() {
|
|||||||
|
|
||||||
mk_tmpdir
|
mk_tmpdir
|
||||||
|
|
||||||
FILE=`mktemp -p $TMPDIR mext_temp_file.XXXXXX`;
|
FILE="$TMPDIR/mext_temp_file";
|
||||||
NUM=0;
|
NUM=0;
|
||||||
REL=0;
|
REL=0;
|
||||||
rm -f $FILE*;
|
|
||||||
|
|
||||||
# Command-line parsing.
|
# Command-line parsing.
|
||||||
args=`getopt -u -n mext r "$@"`;
|
args=`getopt -u -n mext r "$@"`;
|
||||||
@@ -88,15 +84,15 @@ $@ | grep -v '+' | grep -v Variable_name | sed 's/|//g' \
|
|||||||
| while read line; do
|
| while read line; do
|
||||||
if [ "$line" = "" ]; then
|
if [ "$line" = "" ]; then
|
||||||
NUM=`expr $NUM + 1`;
|
NUM=`expr $NUM + 1`;
|
||||||
echo "" > $FILE$NUM;
|
echo "" > "$FILE$NUM"
|
||||||
fi
|
fi
|
||||||
echo "$line" >> $FILE$NUM;
|
echo "$line" >> "$FILE$NUM"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Count how many files there are and prepare to format the output
|
# Count how many files there are and prepare to format the output
|
||||||
SPEC="%-33s %13d"
|
SPEC="%-33s %13d"
|
||||||
AWKS=""
|
AWKS=""
|
||||||
NUM=`ls $FILE* | wc -l`;
|
NUM=`ls "$FILE"* | wc -l`;
|
||||||
# The last file will be empty...
|
# The last file will be empty...
|
||||||
NUM=`expr $NUM - 3`;
|
NUM=`expr $NUM - 3`;
|
||||||
|
|
||||||
@@ -106,19 +102,19 @@ for i in `seq 0 $NUM`; do
|
|||||||
NEXTFILE=`expr $i + 1`;
|
NEXTFILE=`expr $i + 1`;
|
||||||
|
|
||||||
# Sort each file and eliminate empty lines, so 'join' doesn't complain.
|
# Sort each file and eliminate empty lines, so 'join' doesn't complain.
|
||||||
sort $FILE$i | grep . > $FILE$i.tmp;
|
sort "$FILE$i" | grep . > "$FILE$i.tmp"
|
||||||
mv $FILE$i.tmp $FILE$i;
|
mv "$FILE$i.tmp" "$FILE$i"
|
||||||
sort $FILE${NEXTFILE} | grep . > $FILE${NEXTFILE}.tmp;
|
sort "$FILE${NEXTFILE}" | grep . > "$FILE${NEXTFILE}.tmp"
|
||||||
mv $FILE${NEXTFILE}.tmp $FILE${NEXTFILE};
|
mv "$FILE${NEXTFILE}.tmp" "$FILE${NEXTFILE}"
|
||||||
|
|
||||||
# Join the files together. This gets slow O(n^2) as we add more files, but
|
# Join the files together. This gets slow O(n^2) as we add more files, but
|
||||||
# this really shouldn't be performance critical.
|
# this really shouldn't be performance critical.
|
||||||
join $FILE$i $FILE${NEXTFILE} | grep . > $FILE;
|
join "$FILE$i" "$FILE${NEXTFILE}" | grep . > "$FILE"
|
||||||
|
|
||||||
# Find the max length of the [numeric only] values in the file so we know how
|
# Find the max length of the [numeric only] values in the file so we know how
|
||||||
# wide to make the columns
|
# wide to make the columns
|
||||||
MAXLEN=`awk '{print $2}' $FILE${NEXTFILE} | grep -v '[^0-9]' | awk '{print length($1)}' | sort -rn | head -n1`
|
MAXLEN=`awk '{print $2}' "$FILE${NEXTFILE}" | grep -v '[^0-9]' | awk '{print length($1)}' | sort -rn | head -n1`
|
||||||
mv $FILE $FILE${NEXTFILE};
|
mv "$FILE" "$FILE${NEXTFILE}"
|
||||||
SPEC="$SPEC %${MAXLEN}d";
|
SPEC="$SPEC %${MAXLEN}d";
|
||||||
if [ "$REL" = "1" ]; then
|
if [ "$REL" = "1" ]; then
|
||||||
AWKS="$AWKS, \$`expr $i + 3` - \$`expr $i + 2`";
|
AWKS="$AWKS, \$`expr $i + 3` - \$`expr $i + 2`";
|
||||||
@@ -129,10 +125,12 @@ done
|
|||||||
|
|
||||||
# Print output
|
# Print output
|
||||||
AWKCMD="printf(\"$SPEC\n\", \$1, \$2$AWKS);";
|
AWKCMD="printf(\"$SPEC\n\", \$1, \$2$AWKS);";
|
||||||
awk "{$AWKCMD}" $FILE`expr $NUM + 1`;
|
awk "{$AWKCMD}" "$FILE`expr $NUM + 1`"
|
||||||
|
|
||||||
# Remove all temporary files.
|
# Remove all temporary files and the tmp dir.
|
||||||
rm -f $FILE*;
|
rm_tmpdir
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
# Documentation
|
# Documentation
|
||||||
|
Reference in New Issue
Block a user