Skip to content

Instantly share code, notes, and snippets.

@drscotthawley
Last active June 15, 2023 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drscotthawley/570a4aaa0dc1f7c67b8a4f2c422cd883 to your computer and use it in GitHub Desktop.
Save drscotthawley/570a4aaa0dc1f7c67b8a4f2c422cd883 to your computer and use it in GitHub Desktop.
bash aliases for SLURM: "tailjob <jobid>" or just "tailtop" for most recent job
# tails output of any SLURM job that is listed in the queue.
# if job is pending, tailjob will wait until the output file exists
# usage: tailjob <job_id>
tailjob() {
local job_id=$1
if [[ -n "$job_id" ]]; then
local stdout_file=$(scontrol show job "$job_id" | awk -F= '/StdOut=/{print $2}')
echo "Running tail -F $stdout_file"
tail -F "$stdout_file"
else
echo "No job ID provided."
fi
}
# tails the output of your most recent SLURM job in the queue (i.e. top of your squeue -u list)
# usage: just "tailtop" with no arguments
tailtop() {
local job_id=$(squeue -u "$USER" --format="%A %i" --noheader | sort -k2 -n | awk 'END{print $1}')
tailjob "$job_id"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment