bash, ssh and expect to multiple ip addresses


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash, ssh and expect to multiple ip addresses
# 1  
Old 06-20-2010
bash, ssh and expect to multiple ip addresses

Hi, I need script that will allow me to connect to multiple clients using ssh on Ubuntu terminal...
I have a txt file with the ip addresses of clients, i need a script that will connect to everyone one by one and send some commands...
The idea is to check some settings on every client automatically.
They all have same UN and PASS but i can't use public key so I need to use expect probably... Can someone, please, post example how to do that?
Thnx a lot and sorry for any mistakes, my English is not so good.
# 2  
Old 06-21-2010
Try this...

Code:
#!/bin/sh

stty -echo;
read -p "Input password:" A;
stty echo;
echo;
ip_address_list=/tmp/ip_address_list.txt

for HOST in `cat $ip_address_list`
do
echo "Connecting to $HOST"
expect -c "set timeout -1;\
spawn ssh $HOST -l root \"whoami;id;pwd\";\ #you can type any commands you want...
match_max 100000;\
expect *password:*;\
send -- $A\r;\
interact;"
echo "Finished job on $HOST"

done

This User Gave Thanks to Tuxidow For This Post:
# 3  
Old 06-22-2010
thank you very much :-)
I'll try it later, hope it's gonna work...

once again tnx man...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Ubuntu

Expect /bash, 2 ssh login users

HI all i need to connect to about 900 cisco routers and switch to do some configs changes. the issue i am having is that half the devices have one set of username and password and the other half have another username and password. From expect or bash script i can ssh into a device and make... (1 Reply)
Discussion started by: quintin
1 Replies

2. Shell Programming and Scripting

Cisco, 2 ssh logins for expect /bash

HI all i need to connect to about 900 cisco routers and switch to do some configs changes. the issue i am having is that half the devices have one set of username and password and the other half have another username and password. From expect or bash script i can ssh into a device and make... (0 Replies)
Discussion started by: quintin
0 Replies

3. UNIX for Dummies Questions & Answers

How to ping multiple ip addresses?

Hi, I have ip addresses from 192.168.0.1 to 192.168.0.10. I have to ping those series of IP address in single command? Which command i can use? (2 Replies)
Discussion started by: thomasraj87
2 Replies

4. Shell Programming and Scripting

Bash arrays that compare ip addresses.

I've been trying to have an array of ip addresses go through a loop one at a time. Then compare if the current element is in another array of ip addresses. I've traced my error with /bin/bash -x + for c in '"${ip}"' ./netk5: line 65: 50.17.231.23 23.64.146.110 23.64.159.139 107.14.36.129... (17 Replies)
Discussion started by: Azrael
17 Replies

5. Shell Programming and Scripting

Ssh = ssh expect and keep everything not change include parameter postion

I have write a script which contains ssh -p 12345 dcplatform@10.125.42.50 ssh 127.0.0.1 -p 5555 "$CMD" ssh root@$GUEST_IP "$CMD" before I use public key, it works well, now I want to change to "expect", BUT I don't want to change above code and "parameter position" I can post a... (1 Reply)
Discussion started by: yanglei_fage
1 Replies

6. Shell Programming and Scripting

Help with bash script to block IP addresses

I am using a bash script for CentOS 5.5, I found one and modified it, however I want to block the incoming IP addresses and ALLOW the IP addresses that are blocked to send out email. I will use an internal network range for an example, 10.10.10.0/24 (if a lot of spam is incoming) from this range... (0 Replies)
Discussion started by: grifs71
0 Replies

7. Shell Programming and Scripting

could not send commands SSH session with Net::SSH::Expect

I am using Net::SSH::Expect to connect to the device(iLO) with SSH. After the $ssh->login() I'm able to view the prompt, but not able to send any coommands. With the putty I can connect to the device and execute the commands without any issues. Here is the sample script my $ssh =... (0 Replies)
Discussion started by: hansini
0 Replies

8. Shell Programming and Scripting

Expect, SSH and multiple passed commands

Hey Everyone, I have found this script online that has almost all the features I am looking for. However, I do not know enough expect to debug the problem. http://linuxgazette.net/100/misc/tips/sshtool.expect.txt First, it Traps out after it collects the user's password. I do not know... (0 Replies)
Discussion started by: patchsmyle
0 Replies

9. Shell Programming and Scripting

How can i send mail to multiple addresses in same domain in bash?

Suppose i have a txt file that is the list of the addresses,something like: lala0045 john james lala0234 george james and i want to send an email to lala0045@blabla.com and lala0234@blabla.com,the same domain...what is the exact syntax i should use in my script? there is a command... (10 Replies)
Discussion started by: bashuser2
10 Replies

10. Shell Programming and Scripting

Run Multiple Functions over SSH (BASH)

I am trying to write a script that will ssh into a remote machine and recurse through a specified directory, find mp3 files which may be two or three directories deep (think iTunes: music/artist/album/song.mp3), and scp them back to the machine running the script. The script should also maintain... (3 Replies)
Discussion started by: johnnybg00de
3 Replies
Login or Register to Ask a Question