Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Primalot

macrumors newbie
Original poster
Feb 28, 2017
2
0
Sorry for my bad english. But i neeed your help guys!
I need to login via ssh to ubuntu servers, easy yeah?
But I have some troubles:
I need to log at 200 servers
amazement.gif
amazement.gif
amazement.gif
... its possible manually but toooo long and boring here is my routine:
1) ssh -i "PathToKey/Key" ubuntu@serverAddress
Its always asking me to allow or not, and I have to manually type yes/no
2) okey, we are connected at some sec, then i need to run script at ubuntu server, to launch/relaunch process:
#!/bin/bash
nohup myprocess &
(using nohup to allow running my procces even if i close ssh session)
3) close my terminal window
and all this again and again...

Im asking your help to automate all this hell, maybe create file with the list of addresses, maybe connect and one by one, or maybe 5 at one time, typing this "yes", not big timeout (to give time to connect to server), run script, again timeout over 3-5sec to give time to run script, close this session and start another till the list of my servers wont end...

I understand its possible via apple script or automator but i'm noob who needs help)
Thanks for you attention
 

Daniel Santos

macrumors newbie
Nov 1, 2012
26
10
Portugal
for one given server you could do :

ssh -i "PathToKey/Key" ubuntu@serverAddress "nohup myprocess &"

using bash scripting and awk you can make a program that reads a file with a line for each "PathToKey/Key" / user / serverAddress and execute the ssh command for each one.

Hope that helps
 

Primalot

macrumors newbie
Original poster
Feb 28, 2017
2
0
using bash scripting and awk you can make a program that reads a file with a line for each "PathToKey/Key" / user / serverAddress and execute the ssh command for each one.
I understand it but i dont know how to do it)
 

Daniel Santos

macrumors newbie
Nov 1, 2012
26
10
Portugal
As they always use to say : RTFM

If you google : "bash scripting for begginers" and "awk tutorial" it should come up with something. I'll just leave these links below here for you:

http://www.tldp.org/LDP/Bash-Beginners-Guide/html/
https://www.gnu.org/software/gawk/manual/gawk.html

EDIT : Assuming you are not a bash scripter I am posting here a script to do what you want :

1. the file batch_ssh_data.txt has a line with the parameters that vary in the ssh command. Each line has a set of 5 fields separated by the ';' character. You should edit this file putting in your data
2. the file batch_ssh_generate_script.sh is the script that reads the previous file using awk and outputs the ssh commands with the data in it. By running this script you will have the following file:
3. batch_ssh.sh which I am not attaching. This will be generated by the previous script and will contain the concrete ssh commands to launch your processes in the configured servers.

Dont forget to make the file in number 2 executable before running it. And change the extensio to .sh (This forum does not allow the upload of .sh files)
Then run the generated script in number 3.
 

Attachments

  • batch_ssh_data.txt
    104 bytes · Views: 550
  • batch_ssh_generate_script.txt
    275 bytes · Views: 494
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.