Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 06-08-2004, 01:08 PM   #1
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:


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

for i in $SERVERS

ssh $i
cd /directory
rm file.txt


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, 02:38 PM   #2
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 67
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 - | sh"

This will download "" 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, 03:01 PM   #3
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
ssh i$ <<-EOF


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

All times are GMT -5. The time now is 07:29 AM.

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