Created
August 18, 2015 01:11
-
-
Save bholt/f19501ad283dd94b47c7 to your computer and use it in GitHub Desktop.
Slurm SSH Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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