Table of Contents

OAR-related tools

FZF aliases

OAR uses numeric ids for jobs and retype them every time can be really annoying. In case if you have meaningful names, there is a way to quickly select you job for whatever you need. To use those aliases you need installed FZF: https://github.com/junegunn/fzf. In its wiki (https://github.com/junegunn/fzf/wiki/Examples) there are a lot of exciting examples how to use fzf with shell, vim and git. You need to put snippets below in your .bashrc (or .zshrc) and restart your shell.

Quickly connect to a passive job

  jsh() {
    myhost="$(hostname)"
    if [ `hostname -s` = 'edgar' -o `hostname -s` = 'access2-cp' ]; then
      local stats jid
      stats=$(oarstat --user=$USER --format 2 | tail -n +3 | grep -v '^[0-9]\+\s\+W') &&
      jid=$(echo "$stats" | tac | fzf) &&
      oarsub -C $(echo "$jid" | awk '{print $1}')
    else
      echo -e "Run it on edgar\n\n"
      ssh -t edgar jsh
    fi
  }

A few explanations why it works. oarstat command lists all jobs for a given user, tail removes the header, grep removes all waiting jobs (you can't connect to them yet), tac reverses the order of lines. fzf is a fuzzy searcher, it outputs the line you chose in stdout. It goes to awk that cuts the job_id and passes it to oarsub. So to use it just type jsh and type some words from the name of job you are looking for or use Ctrl-j/Ctrl-k to go down/up. When you are done, press enter and enjoy your ssh tunnel.

Quickly open a log file

jlog() {
if [ `hostname -s` = 'edgar' ]; then
    local stats jid
    stats=$(oarstat --user=$USER --format 2 | tail -n +3 | grep -v '^[0-9]\+\s\+W') &&
    jid=$(echo "$stats" | tac | fzf) &&
    jid=$(echo "$jid" | awk '{print $1}')
    less +GF $HOME/<your_log_dir>/*.$jid.stderr
else
    echo "Run it on edgar\n\n"
    ssh edgar
fi
}

The idea is the same essentially, just instead of oarsub, it calls less pager. You need to put the path to your log directory and probably change stderr to stdout (if you want). less is automatically jumps to the end of file (+G option) and turns into continuous reloading mode (F option).

Kill your jobs by names

jkill() {
if [ `hostname -s` = 'edgar' ]; then
    local stats jid
    stats=$(oarstat --user=$USER --format 2 | tail -n +3) &&
    jid=$(echo "$stats" | tac | fzf -m) &&
    oardel $(echo "$jid" | awk '{print $1}' | tr '\n' ' ')
else
    echo "Run it on edgar\n\n"
    ssh edgar
fi
}

Essentially the same except we don't filter out waiting jobs (hence no grep), fzf runs in multi-choice mode (-m flag), you can choose a few jobs using tab and to concatenate job ids into one line we use tr.