Skip to content

Instantly share code, notes, and snippets.

@eddiebergman
Last active January 30, 2023 09:40
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 eddiebergman/130c29f6cd467718dd23c826f475a168 to your computer and use it in GitHub Desktop.
Save eddiebergman/130c29f6cd467718dd23c826f475a168 to your computer and use it in GitHub Desktop.
A more informative `sq` command
fudge() {
# Does some simple formatting for general things
# * Highlights based on status code
# * Highlight your name
# * Dim some things
# https://stackoverflow.com/a/33206814
# https://www.linuxquestions.org/questions/linux-newbie-8/tput-for-bold-dim-italic-underline-blinking-reverse-invisible-4175704737/
green=$(tput setaf 2)
orange=$(tput setaf 3)
bold=$(tput bold)
dim=$(tput dim)
italic=$(tput sitm)
X=$(tput sgr0)
replace () {
sed -r "s/${1}/${2}/g"
}
# This will replace the current standard in that was piped to this function
replace " ${USER}" "${bold} ${USER}${X}" \
`#Dim the last column` \
| replace "([^ ]*)\\s*$" "${dim}\\1${X}" \
`# Dim partitions` \
| replace " ([^ ]*cpu[^ ]*) " "${dim} \\1 ${X}" \
| replace " ([^ ]*gpu[^ ]*) " "${dim} \\1 ${X}" \
`# Color code pending and ready jobs` \
| replace \
"(.*)( R )(.*)( [0-9][^ ]*)\/([^ ]*[0-9])" \
"\\1${green}\\2${X}\\3${green}${italic}\\4${X}\/${green}${bold}\\5${X}" \
| replace \
"(.*)( PD )(.*)( [0-9][^ ]*)\/([^ ]*[0-9])" \
"\\1${orange}\\2${X}\\3${orange}${italic}\\4${X}\/${orange}${bold}\\5${X}" \
`# Dim the seperator` \
| replace " \| " "${dim} \| ${X}" \
`# Just a generic make the R and PD colored` \
| replace "(.*)( R )(.*)" "\\1${green}\\2${X}\\3" \
| replace "(.*)( PD )(.*)" "\\1${orange}\\2${X}\\3"
}
sq () {
# Just has a "master" format with everything I care about
# https://slurm.schedmd.com/squeue.html
format="%.20i | %2t %12R | (%1D %.2C %.7m) | %.10L/%10l | %.10u | %20j"
squeue "$@" -o "${format}" | fudge --p
}
@eddiebergman
Copy link
Author

Uploading Screenshot_2023-01-30_09-50-04.jpg…

@eddiebergman
Copy link
Author

eddiebergman commented Jan 30, 2023

This one requires fzf to be installed. It lets you select a job and spits out a command to limit the number of concurrent tasks being run.

selectjob() {
    squeue -u "${USER}" -h --format "%i | %12R | %.10L/%10l | %j" \
      | fzf \
      | cut -f1 -d"|" \
      | cut -f1 -d"_" 
}

joblimit () {
    selectjob | xargs -I '{}' echo "scontrol update JobId={} ArrayTaskThrottle="
}

Outputs the following:

$ joblimit
# Interactive selection of the job
scontrol update JobID=<selected> ArrayTaskThrottle=

You can then copy the above command and put in your limit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment