summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Laska <jlaska@redhat.com>2011-05-06 08:33:52 -0400
committerJames Laska <jlaska@redhat.com>2011-05-06 08:33:52 -0400
commit8125e66216dace26ccf89b77684d155fe00bc574 (patch)
tree03aa57bc736a6c463a18f2c4ff56bece26954f71
parent9ff9bd5f62fefd02bb92f1024c8e637521b0d112 (diff)
downloadscripts-8125e66216dace26ccf89b77684d155fe00bc574.tar.gz
scripts-8125e66216dace26ccf89b77684d155fe00bc574.tar.xz
scripts-8125e66216dace26ccf89b77684d155fe00bc574.zip
Add autotest library compression helper script
-rwxr-xr-xcompress_large_files57
1 files changed, 57 insertions, 0 deletions
diff --git a/compress_large_files b/compress_large_files
new file mode 100755
index 0000000..e5c8a96
--- /dev/null
+++ b/compress_large_files
@@ -0,0 +1,57 @@
+#!/bin/bash
+#
+# Recursively compress any files greater than a supplied MINSIZE (-s), starting
+# from the supplied DIRECTORY (-d).
+#
+
+error() {
+ echo "Error: $1"
+ exit 1
+}
+
+usage() {
+ echo "Usage: $0 <options>
+
+Where <options> include:
+ -d DIRECTORY - Specify directory to recurse
+ -s MINSIZE - Minimum file size in MiB to compress
+ -n - Don't make changes, just display
+"
+ exit 1
+}
+
+# Initialize variables
+COMPRESS_SUFFIX=".gz"
+COMPRESS_CMD="gzip -v --suffix ${COMPRESS_SUFFIX}"
+
+# Process cmdline arguments
+DRYRUN=0
+MINSIZE=""
+COMPRESS_DIR=""
+while getopts "ns:d:h" options; do
+ case $options in
+ n ) DRYRUN=1 ;;
+ s ) MINSIZE=$OPTARG ;;
+ d ) COMPRESS_DIR=$OPTARG ;;
+ \?|h ) usage ;;
+ * ) usage ;;
+ esac
+done
+
+# Validate input
+test -z "${COMPRESS_DIR}" && error "Missing -d argument"
+test -z "${MINSIZE}" && error "Missing -s argument"
+
+# Find files to compress using the supplied arguments
+find "${COMPRESS_DIR}" -type f -not -name "*${COMPRESS_SUFFIX}" -size +"${MINSIZE}"M |
+while read line
+do
+ if [ ${DRYRUN} -eq 1 ]; then
+ echo "Would run: ${COMPRESS_CMD} ${line}"
+ else
+ ${COMPRESS_CMD} ${line}
+ # Create symlink to original file
+ ln -s $(basename $line).gz ${line}
+ fi
+done
+