LinuxQuestions.org
Visit Jeremy's Blog.
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 06-08-2004, 12:08 PM   #1
Namuna
LQ Newbie
 
Registered: May 2004
Posts: 2

Rep: Reputation: 0
Bash, SSH and scripting.


Hello all,

I'm new to the forums, so if this is the wrong place to post this, please let me know. I've also done a few searches and didn't get an answer, so I do apologize if this has been covered.

Here's what I'm trying to do...

We use a compute farm to calculate and process the request from a main application...Basically this means sometimes having to make the same add/change/delete to a whole bunch of machines.

What I usually do is terminal into 1 box, and then ssh into the subsequent boxes to make the changes...As you can guess, it's tedious.

I've tried to script the process of ssh'ing to the boxes and the commands, but I'm doing something wrong...I'm doing something like:

------------
#!/bin/bash

SERVERS=`cat /usr/servers.txt` #has list of the machines to be updated

for i in $SERVERS
do

ssh $i
cd /directory
rm file.txt
exit

done
-------------

The commands aren't making their way to each of the boxes I'm ssh'ing to. What am I doing wrong?

thanks much!
 
Old 06-08-2004, 01:38 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
Welcome to LQ.

All of the commands that you place in your bash script will be run on the local box so it is trying to cd and rm on your machine. To run a command on a remote box you can use the syntax:
ssh user@host command

If you want to run a whole script on a remote box then a good technique is to upload the script that is to be run remotely to a web server. Then when you execute the ssh command - use:
ssh user@host "wget -qO - http://www.yourhost.com/script.sh | sh"

This will download "script.sh" and run it on the server that you ssh to. This is also quite useful for automatic updates as you can schedule the wget command using cron.
 
Old 06-08-2004, 02:01 PM   #3
Namuna
LQ Newbie
 
Registered: May 2004
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks for the reply,

One of the local gurus here helped me out with this, he said to use a 'here' redirect? something like this...

-------------
SERVERS=`cat servers.txt`

for i in $SERVERS
do
ssh i$ <<-EOF
command
EOF
done
 
  


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
Bash scripting vinoth.ilango Solaris / OpenSolaris 6 10-29-2004 04:41 AM
BASH If-then-else Scripting Help xianzai Programming 4 10-29-2004 04:09 AM
Bash scripting... ssh? TheIrish Programming 4 11-27-2003 08:37 AM
bash scripting -=MaGo=- Programming 16 08-30-2003 07:07 PM
BASH scripting help Chucklez Linux - Newbie 4 12-12-2002 12:07 PM


All times are GMT -5. The time now is 07:32 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration