LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-25-2011, 11:53 AM   #1
dnoy
Member
 
Registered: Nov 2007
Posts: 69

Rep: Reputation: 15
performing tasks on a list of IPs


i want to create a text file that has a list of IPs that are seperated by a carriage return.

I would then like to loop through these until the end of the file. Each Ip will need to have the following ran on it:

spawn ssh root@IP
expect "Password:"
send "password"
expect "#"
send "mkdir /stuff\r"
expect "#"

#***************************************

#then i will need to run this....


#***************************************

spawn scp /stuff/stuff2 root@IP:/etc/sysconfig/
expect "Password:"
send "password"
expect "#"
spawn scp /stuff/morestuff /stuff/betterstuff root@IP:/scripts
expect "Password:"
send "password"
expect "#"



your help is greatly appreciated.

Thank you
 
Old 03-25-2011, 12:08 PM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Code:
#!/bin/bash -x

file="data.txt"

if [ ! -f $file ]; then
        echo "file doesn't exist";
        exit;
fi

exec 0<"$file"
while read -r line
do #anything from here on, can be used against each $line in the file
 spawn ssh root@$line
 expect "Password:"
 send "password"
 expect "#"
 send "mkdir /stuff\r"
 expect "#"
done
You can tweak it a bit to get it to do what you need, but that is the basic shape of what you are asking for. the '-x' after bash at the top, is for troubleshooting. you can remove it once it works for you.

Last edited by szboardstretcher; 03-25-2011 at 12:10 PM.
 
Old 03-25-2011, 12:17 PM   #3
dnoy
Member
 
Registered: Nov 2007
Posts: 69

Original Poster
Rep: Reputation: 15
i tried something like this before but expect is not working as it needs

#!/usr/bin/expect
 
Old 03-25-2011, 12:29 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,417
Blog Entries: 55

Rep: Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627
Quote:
Originally Posted by dnoy View Post
Each Ip will need to have the following ran on it
Apart from the obvious don't allow root access over the network and a pointer to using pubkey auth did you know there's applications to execute commands on multiple hosts using SSH like Clusterit, Clusterssh, Dancer's Shell, PSSH, MUC, SwitchTower and others like Rgang, Tentakel, Fanout?
 
Old 03-25-2011, 12:32 PM   #5
dnoy
Member
 
Registered: Nov 2007
Posts: 69

Original Poster
Rep: Reputation: 15
i am VERY limited on what i can install on the linux boxes as they are appliances and locked down.... at this point i think sshing in as root is my only option
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Show list of running tasks from services / init.d in Debian / Ubuntu? browny_amiga Linux - General 1 01-23-2009 05:00 AM
LXer: Performing Basic Tasks with MySQL 4.1 and Above, using mysqli with ... LXer Syndicated Linux News 0 07-02-2006 09:33 PM
Make tasks invisible in Gnome Window List 2.4.0 Zanneth Linux - General 1 04-11-2004 08:45 PM
IPs list eduac Linux - Networking 6 08-14-2003 01:25 PM
performing tasks as root curos Linux - Newbie 1 08-06-2003 03:17 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration