
Untitled
By: a guest on
May 27th, 2012 | syntax:
None | size: 0.81 KB | hits: 17 | expires: Never
#!/bin/bash
<<EXPLAIN
run a job and save to log files with a useful name
EXPLAIN
J=$1
A=($@)
# number of args
N=${#A[*]}
# drop the first arg (job-name)
BARGS=("${A[*]:1:$N}")
if [ "x$J" == "x" ]; then
echo "specify a job name as first argument."
echo "usage: cat some.sh | $0 job-name"
exit 1
fi
DATE=$(date +"%d-%m-%Y")
ERR=$J.%J.err
OUT=$J.%J.out
# save command to a script.
SH=$J.sh
if [ -d logs/ ]; then
ERR=logs/$ERR
OUT=logs/$OUT
SH=logs/$SH
fi
echo "#!/bin/sh" > $SH
echo "# run on:" $DATE >> $SH
while read aline; do
echo $aline
done >> $SH
R=$(bsub -J $1 -e "$ERR" -o "$OUT" "$BARGS" < $SH)
JOB_NUM=$(echo $R | perl -p -e 's/.+<(\d+)>.+/$1/')
if [ ! -d logs/ ]; then
rm $J.sh
else
mv logs/$J.sh logs/$J.$JOB_NUM.sh
fi
# parse and echo the job-number
echo $JOB_NUM || $R