SSH into gateway server, request compute node, and automatically ssh into the allocate node


This Content is from SuperUser. Question asked by Jacobus Smit

Specifically I am using the lisa compute terminals, but I haven’t been able to find out whether this is possible and how to if so. The steps I (believe I) want to achieve are:

  1. Connect to user@gateway,
  2. Request a compute node with X cores for Y time,
  3. Wait for the node to be allocated,
  4. ssh into this node.

Ideally I want to set up my ssh config to allow me to allocate and use a compute terminal in a single ssh command, but for the time being I began writing a script to do what I want.


ssh user@host salloc -n ${1:-1} -c 4 -t ${2:-00:00:01} |
while IFS= read -r line; do
    if grep -o "r[0-9]+n[0-9]+" "$line" ; then
        ASSIGNEDHOST = "`grep -o "r[0-9]+n[0-9]+" "$line"`"
        echo "$ASSIGNEDHOST"
ssh user@"$ASSIGNEDHOST".host

Unfortunately what happens now is that it sshes in fine and allocates a node, but doesn’t go from there. How should I escape the while loop once it detects (via grep) an allocated node?


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from SuperUser , is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?