I am running an experiment with several instances - one server node with a floating IP address, and several client nodes without - in which I need to use the server node to access the client nodes. This is fine with SCP as it is a one-off process but SSH has given me more problems - especially considering that I need to do this particular SSH via Python.
Here is the script being used:
user='cc'
host_keyname='my_chameleon_key.pem'
port=22
script = '#!/bin/bash' '\n' \
'USER="' + user + '"' '\n' \
'KEY_NAME="' + host_keyname + '"' '\n' \
'PORT_NUMBER='+ str(port) + '\n' \
'CLIENT_IPS=(' + ip_string + ')' '\n' \
'for ip in "${CLIENT_IPS[@]}"' '\n' \
'do' '\n' \
' ssh -i ~/.ssh/${KEY_NAME} ${USER}@${ip} << ENDHERE' '\n' \
' git clone https://github.com/pari685/AStream.git' '\n' \
' ENDHERE' '\n' \
'done' '\n'
And the Paramiko call:
key = {
"key_filename": key_path,
}
with Connection(host=host_ip, user="cc", connect_kwargs=key) as c:
c.run(script)
All of the client IPs are stored space delimited in the string ip_string
and host_ip
is a string containing just my server node.
Unsurprisingly, Python is unhappy with my ENDHERE. I'm not sure how to exit the internal hop in the script's for loop. What should I be doing instead?