Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 27th, 2012  |  syntax: None  |  size: 0.81 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2.  
  3. <<EXPLAIN
  4. run a job and save to log files with a useful name
  5. EXPLAIN
  6.  
  7. J=$1
  8. A=($@)
  9. # number of args
  10. N=${#A[*]}
  11. # drop the first arg (job-name)
  12. BARGS=("${A[*]:1:$N}")
  13.  
  14.  
  15. if [ "x$J" == "x" ]; then
  16.     echo "specify a job name as first argument."
  17.     echo "usage: cat some.sh | $0 job-name"
  18.     exit 1
  19. fi
  20.  
  21. DATE=$(date +"%d-%m-%Y")
  22. ERR=$J.%J.err
  23. OUT=$J.%J.out
  24.  
  25. # save command to a script.
  26. SH=$J.sh
  27.  
  28.  
  29. if [ -d logs/ ]; then
  30.     ERR=logs/$ERR
  31.     OUT=logs/$OUT
  32.     SH=logs/$SH
  33. fi
  34. echo "#!/bin/sh" > $SH
  35. echo "# run on:" $DATE >> $SH
  36.  
  37.  
  38. while read aline; do
  39.     echo $aline
  40. done >> $SH
  41.  
  42. R=$(bsub -J $1 -e "$ERR" -o "$OUT" "$BARGS" < $SH)
  43. JOB_NUM=$(echo $R | perl -p -e 's/.+<(\d+)>.+/$1/')
  44.  
  45. if [ ! -d logs/ ]; then
  46.     rm $J.sh
  47. else
  48.     mv logs/$J.sh logs/$J.$JOB_NUM.sh
  49. fi
  50. # parse and echo the job-number
  51. echo $JOB_NUM || $R