LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-18-2012, 01:05 AM   #1
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Run a script on multiple systems


Let's say I have a script and in this script I have a loop and a list of different systems, so that when I invoke the script from my local system, it goes to different systems, login into them one by one and fetch some required data as mentioned in the scrpit. So how we can achieve this?
#!/bin/bash
systemslist=/tmp/systems.txt
for system in $systemslist
do
ssh user@$system "date" > /tmp/output.txt
done

Problem 1# Every system requires a password to login into it, so how to pass password in the script?
Problem 2# How to save the output of command between do and done in the system from where I am running it (else it will save the output file in different systems)?

Last edited by shivaa; 10-18-2012 at 01:09 AM.
 
Old 10-18-2012, 01:17 AM   #2
nugat
Member
 
Registered: Sep 2012
Posts: 122

Rep: Reputation: 31
Quote:
Originally Posted by meninvenus View Post
Problem 1# Every system requires a password to login into it, so how to pass password in the script?
Use Expect, a tcl programming language designed to write programs to run non-interactively which usually require input. Or *much* better, set up SSH public/private keys and do password-less authentication. Look into the ssh-keygen and ssh-copy-id commands to help you w/this. They are part of the OpenSSH suite and are likely already on your system.

Quote:
Problem 2# How to save the output of command between do and done in the system from where I am running it (else it will save the output file in different systems)?
The way you've written it, it should NOT write it to the remote system, but to the local one. To force it to write it remotely, you'd normally do something like:
Code:
ssh user@sytem "date >/tmp/remote.txt"
Have you verified that it isn't writing locally or is that just a theory?
 
  


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
shell script ssh to multiple servers hoa Linux - Newbie 1 06-08-2012 01:39 AM
[SOLVED] Run shell script on multiple linux servers vanish78 Linux - Newbie 5 05-16-2012 11:42 AM
help with script to check processes on multiple servers ncsuapex Programming 7 06-10-2008 12:02 PM
How to run multiple X servers. samkraju Red Hat 1 12-30-2007 12:07 PM
Can't run multiple X servers jojotx0 Linux - Software 3 08-12-2006 11:31 AM


All times are GMT -5. The time now is 03:09 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration