From: Colin Patrick Mccabe Date: Wed, 26 Jun 2013 08:36:33 +0000 (-0700) Subject: add dripfeed.sh X-Git-Url: http://club.cc.cmu.edu/~cmccabe/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=154c1fc8b6b9e79647606f37f84c8201b9371b73;p=cmccabe-bin add dripfeed.sh Signed-off-by: Colin McCabe --- diff --git a/dripfeed.sh b/dripfeed.sh new file mode 100755 index 0000000..3b229a7 --- /dev/null +++ b/dripfeed.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +# +# dripfeed.sh +# +# A script to perform several actions at a time from a file. +# +# Colin McCabe +# + +die() { + echo $1 + exit 1 +} + +usage() { + cat </dev/null && break + done + echo "nline = $nline, nlines = $nlines" + [ $nline -gt $nlines ] && exit 0 + line=$(head -n ${nline} ${input_file} | tail -n 1) + echo $line + $line + done +} + +input_file="" +num_procs=1 +while getopts "f:hp:" flag; do + case $flag in + f) input_file=$OPTARG;; + h) usage; exit 0;; + p) num_procs=$OPTARG;; + *) echo "getopts error" + echo + usage + exit 1;; + esac + #echo "$flag" $OPTIND $OPTARG +done +[ x${input_file} == x ] && die "you must supply an input file with -f" +nlines=$(wc -l "${input_file}" | awk '{ print $1 }') +[ $? -ne 0 ] && die "wc -l ${input_file} failed" + +for (( idx=0; idx < ${num_procs}; idx++ )) do + { dripfeed; } & +done +wait + +exit 0