Skip to content

Instantly share code, notes, and snippets.

@bholt
Created August 18, 2015 01:11
Show Gist options
  • Save bholt/f19501ad283dd94b47c7 to your computer and use it in GitHub Desktop.
Save bholt/f19501ad283dd94b47c7 to your computer and use it in GitHub Desktop.
Slurm SSH Script
#!/bin/bash
# usage: slurm-ssh [host] [shell]
# e.g.: salloc -N2 slurm-ssh
# n01 (salloc n[01,04]) >
# or:
# slurm-ssh n01
# or:
# slurm-ssh n01 zsh
DIR=$(pwd)
if [ -n "$SLURM_NODELIST" ]; then
first=$(scontrol show hostname $SLURM_NODELIST | head -n1)
fi
if [ "$#" -gt 2 ]; then
exec ssh -q "cd DIR; $@"
else
host=${1-$first}
env=$(printenv | grep SLURM | sed -rn "s/=(.*)/='\1'/p" | paste -d' ' -s)
exec ssh -q $host -t "cd $DIR; $env ${2-$SHELL} --login"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment