Skip to content
Snippets Groups Projects
latest_run 2.35 KiB
Newer Older
  • Learn to ignore specific revisions
  • Whitney Armstrong's avatar
    Whitney Armstrong committed
    #!/bin/bash
    
    function print_the_help {
      echo "USAGE: latest_run [--type=coin] "
      echo "  OPTIONS: "
      echo "            -t,--type          Run type (coin, hms, shms) [default: coin]"
      echo "            -d,--dir           raw dir to use [default: /net/cdaq/cdaql3data/coda/data/raw]"
      echo "            -c,--cache         Use the mss cache directory (same as using --dir /cache/hallc/spring17/raw)"
      echo "            -h,--help          print help"
      exit 
    }
    
    function yes_or_no {
      while true; do
        read -p "$* [y/n]: " yn
        case $yn in
          [Yy]*) return 0 ;;
          [Nn]*) echo "No entered" ; return 1 ;;
        esac
      done
    }
    #yes_or_no "Upload these ? " && some_command
    
    #if [[ $# -eq 0 ]] ; then
    #  print_the_help
    #  exit 
    #fi
    
    CODATYPE=coin
    USE_RAW_DIR=
    
    POSITIONAL=()
    while [[ $# -gt 0 ]]
    do
      key="$1"
    
      case $key in
        -h|--help)
          shift # past argument
          print_the_help
          ;;
        -t|--type)
          CODATYPE="$2"
          shift # past argument
          shift # past value
          ;;
        -d|--dir)
          USE_RAW_DIR="$2"
          
          shift # past argument
          shift # past value
          ;;
        -c|--cache)
          USE_RAW_DIR="/cache/hallc/spring17/raw"
          shift # past value
          ;;
        #-a|--all)
        #  LOG_ALL_PLOTS=1
        #  shift # past argument
        #  #shift # past value
        #  ;;
        #-o|--online-only)
        #  ONLINE_ONLY=1
        #  shift # past argument
        #  #shift # past value
        #  ;;
        *)    # unknown option
          #POSITIONAL+=("$1") # save it in an array for later
          echo "unknown option $1"
          print_the_help
          shift # past argument
          ;;
      esac
    done
    set -- "${POSITIONAL[@]}" # restore positional parameters
    
    #if [[ -n "${LOG_ALL_PLOTS}" ]] ; then
    #  ONLINE_ONLY=
    #fi
    #echo "Number files in SEARCH PATH with EXTENSION:" $(ls -1 "${SEARCHPATH}"/*."${EXTENSION}" | wc -l)
    #if [[ -n $1 ]]; then
    #    echo "Last line of file specified as non-opt/last argument:"
    #    tail -1 "$1"
    #fi
    
    files=
    #if [[ "${CODATYPE}" == "coin" ]] ; then
      raw_dir=/net/cdaq/cdaql3data/coda/data/raw
      rawcopied_dir=/net/cdaq/cdaql3data/coda/data/raw.copiedtotape
    
      if [[ -n "${USE_RAW_DIR}" ]] ; then
        files=(${USE_RAW_DIR}/${CODATYPE}_*.dat)
      else
        files=(${rawcopied_dir}/${CODATYPE}_*.dat ${raw_dir}/${CODATYPE}_*.dat)
      fi 
    
      for afile in "${files[@]}"
      do 
        basename  $afile  .dat
      done | sort  | tail -n 1 | sed "s/${CODATYPE}_all_//g" | sed 's/^0*//' 
    #fi