Shell script to connect to multiple ssh servers

Login or Register for Dates, Times and to Reply

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to connect to multiple ssh servers
# 1  
Shell script to connect to multiple ssh servers


I have access to several linux servers (mostly centos based) located in a DC in another country.
from day to day I need to login to each of them to do some work (they dont have gui/window manager installed, I work only from console), or even to just do a check like df -h for disc usage.

I have stored all the ssh passes to a locked file and each time I have to run putty, copy/paste the pass for each server (I have locked root login, you have to authenticate as a user first then run su)etc etc.

My idea is to create a script (that will be localy in a linux vm) that will

1) just do a complete ssh connection to the server just by typing a command for example the server's name "server1"

2)run a command in a server and give me the ouput, like df -h in "server1"

about the 1st , if straight root connection was enabled it would be easy, but I dont know how to do it now that root login is not permited.
# 2  
What have you done?
# 3  
I think the first thing you should do is set up key based authentication, so you do not need to enter the password every time you log in to a server. As you are looking for a script solution rather than an alias one, and you want to do several servers at once, key based auth is one of the basic requirements.

Secondly, you need to see if you can set up a (limited) passwordless sudo environment, so you can run certain commands using sudo without being asked for a password.

If you do both of these, you would be able to script what you want to do.

For single commands, it might be worth looking at creating a simple alias though...
# 4  
Great!! Smilie

I would recommend you to look into commands like rexec/remsh, ssh.

Hope this feeds you Smilie
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #39
Difficulty: Easy
IC chips for computer systems are usually made of silicone.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Assistance to connect to servers via ssh once and collect various commands into separate variables

Hello, We use as bash script to connect to servers listed in an .csv file to issue commands against these servers and retrieve data to be saved in a .csv file. The data we want to collect is saved in variables. We issue an ssh command for each variable we want to capture. I'm thinking this is... (9 Replies)
Discussion started by: greavette
9 Replies

2. Shell Programming and Scripting

Shell script to ping multiple servers

Hi I did the following script to ping multiple servers, but I keep on receiveing duplicate emails for one server that is down: #!/bin/bash date cat /var/tmp/servers.list | while read output do ping -c 1 "$output" > /dev/null if ; then echo "node $output is up" else ... (10 Replies)
Discussion started by: fretagi
10 Replies

3. UNIX for Dummies Questions & Answers

How can we connect multiple servers at a time?

help me (0 Replies)
Discussion started by: sonu pandey
0 Replies

4. Shell Programming and Scripting

Script to add new users to a group on multiple servers using SSH

Hi Experts, I am new to scripting. We have around 400 Linux servers in our environment. I want to add a new user to a perticular group on all the servers using SSH. Requirements: 1) Need to take the server names from a text file. 2) Login into each server and check whether perticular... (1 Reply)
Discussion started by: Satya1983
1 Replies

5. Shell Programming and Scripting

run vi/vim encrypted shell script without decryption on multiple servers

Hello Everyone, How do we run vi/vim encrypted shell script without decryption on multiple servers. It is a simple bash script and vim -nx <filename> has been used to encrypt with desired password. Now I have few errors, the syntax is absolutely fine as I have run that script multiple times on... (0 Replies)
Discussion started by: lovesaikrishna
0 Replies

6. Shell Programming and Scripting

Shell script to change the password on multiple servers in linux

Can any one please let me know the shell script to change the password for a particular user on multiple linux servers. (2 Replies)
Discussion started by: s_madras
2 Replies

7. Shell Programming and Scripting

connect to multiple servers using SSH and execute commands

Requirement: Run a shell script with below inputs file name checksum path the script should go to multiple servers (around 35) and verify the input cksum and if there is a mismatch display a simple message to the user that cksum verification failed. host details, user id /... (1 Reply)
Discussion started by: amicableperson
1 Replies

8. Shell Programming and Scripting

Connect two servers in shell script

Hello all, I know that is a question which has made too many times, and I have been looking into the threads but all posted was not sucessfully for me so... I need a shell script which connect two unix servers, but NOT using ssh... Is there another way to do it? I've tried ssh but it didn't... (1 Reply)
Discussion started by: Geller
1 Replies

9. Shell Programming and Scripting

shell script for how to connect to a remote server by using ssh

i want to connect to a remote server through ssh. i have to also provide password within that script. after connecting to the remote server i want to do some operations like grep,cd etc can u pls help me to wite a script. Thanks (1 Reply)
Discussion started by: millan
1 Replies

10. Shell Programming and Scripting

Shell/perl script to connect to different servers in single login in teradata

Hi, I want to write a shell script to compare two tables in teradata.these tables are present on different servers. I want to connect to both servers in single login in order to fetch and compare the data in one go. Thanks (1 Reply)
Discussion started by: monika
1 Replies

Featured Tech Videos