Skip to content

Shane's shell tips

Shane Neph edited this page Aug 21, 2025 · 13 revisions

.bashrc tips found in ~sjn/.bashrc

sc() {
  params=""
  if (( $# != 0 )); then
    params="$@"
  fi
    squeue $params -o '%.8u %.2t %.6C %R' --noheader --array | awk -v me=$(whoami) 'BEGIN {mecntr=0;waitcntr=0;allwaitcntr=0;smartcntr=0;neversatisfiedcntr=0;allsmartcntr=0;allneversatisfiedcntr=0;allnum=0} {num=$3; allnum+=num; if ($2~/R/) { } if ($2~/PD/) {allwaitcntr+=num; if ($4~/Dependency/ || $4~/JobHeld/) allsmartcntr+=num; if ($4~/DependencyNeverSatisfied/) allneversatisfiedcntr+=num;} if ($1==me) {mecntr+=num; if ($2~/PD/) {waitcntr+=num; if ($4~/Dependency/ || $4~/JobHeldUser/) smartcntr+=num; if ($4~/DependencyNeverSatisfied/) neversatisfiedcntr+=num;}} } END {print " All CPUs: " allnum; print "   Running: " allnum-allwaitcntr; print "   Waiting: " allwaitcntr; print "      Resource: " allwaitcntr-allsmartcntr; print "      Designed: " allsmartcntr; print "      Orphaned: " allneversatisfiedcntr; print " My CPUs: " mecntr; print "   Running: " mecntr-waitcntr; print "   Waiting: " waitcntr; print "      Resource: " waitcntr-smartcntr; print "      Designed: " smartcntr; print "      Orphaned: " neversatisfiedcntr; }' && date;
}

sc0() { sc -p cpu-g2 -A stergachislab; }
sc1() { sc -p compute-ultramem -A stergachislab; }
sc2() { sc -p ckpt; }

cluster-wide on the checkpoint partition

> sc2

sc-all

synchronize Slurm jobs : minimalist style

Example: loop over each region of a fasta's fai file and do work. Wait for all work to finish before moving on in tcsh script (bash is similar)

#!/bin/tcsh

# jobs run in parallel on the cluster, final script just forces the tcsh script to wait for
#  all jobs to finish before moving on further in the tcsh script.

set mem = "4G"
set threads = 1
set jobids = ()

foreach chr (`awk '{ print $1 }' some.fa.fai`)
  set jid = `sbatch --parsable -A stergachislab -p cpu-g2 -J job.$chr \
    --mem=$mem --time=8:00:00 --ntasks=$threads \
    --export=ALL,CHR=$chr your_script.tcsh`
  set jobids = ( $jobids $jid )
end

# Join job IDs with colons
set deps = `echo $jobids | tr ' ' ':'`

# Submit waiter job (alternatively: while(true) loop that sleeps and polls)
sbatch --wait --dependency=afterok:$deps --wrap "echo 'All chromosome jobs complete.'"

echo "everything is done!"

exit 0

Clone this wiki locally