0

I want to write a fish script to run Locust on the amazon servers. I wrote the code as below, the problem is that when the shell connects to first server it cant send the other commands there.

Any helps, recommedationa are appreciated.

set labs 'ubuntu@compute1.amazonaws.com' 'ubuntu@compute2.amazonaws.com' 'ubuntu@compute3.amazonaws.com' 'ubuntu@compute4.amazonaws.com' 
set key /Users/mesutgunes/Desktop/project-key.pem

for lab in $labs
    ssh -i $key $lab 
    cd /path/to/project/
    screen
    locust -f file.py --master
    exit
end
Mesut GUNES
  • 7,089
  • 2
  • 32
  • 49

1 Answers1

1

You need to pass the commands you want to run as the final argument to the ssh command.

for lab in $labs
    ssh -i $key $lab screen locust -f /path/to/project/file.py --master
end

In this case that will work fine I think. Be careful when the remote command is more complex, especially if it contains quoted strings, as you can end up with a right dog's dinner of nested quotes! If that happens, you're usually best to scp a script across, then run it using ssh.

IBam
  • 10,114
  • 1
  • 24
  • 36
  • thank you it works. I have receiving two message: `Must be connected to a terminal.` and `bash: =: command not found`. I also wonder normally I must pres `enter` key to activate `screen`, how do I handle it? – Mesut GUNES Oct 15 '15 at 14:07
  • Change the command to: `command='cd /path/to/project/; screen locust -f file.py --master'` That runs screen with that single command. Could shorten even further to: `command='screen locust -f /path/to/project/file.py --master'` – IBam Oct 15 '15 at 14:18
  • Actually once you've done that, may as well inline the command - I'll update my answer – IBam Oct 15 '15 at 14:20