UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #16  
Old October 4th, 2004, 01:23 PM
andyb1ack andyb1ack is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 60 andyb1ack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 14 sec
Reputation Power: 4
Ooops. My fault, that was never going to work. This is the bare bones:

Code:
for NODENAME in LIGHTNING2 RANGER
do
  echo
  echo Running the hostname command against ${NODENAME}
  ssh -n username@${NODENAME} hostname
done

Reply With Quote
  #17  
Old October 8th, 2004, 02:56 PM
StevenC's Avatar
StevenC StevenC is offline
PHP & Java Error Master
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2003
Location: My Computer
Posts: 1,218 StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 1 h 32 m 40 sec
Reputation Power: 15
Code:
$. ./loop_test

Running the hostname command against LIGHTNING2
username@lightning2's password:
lightning2

Running the hostname command against RANGER
username@ranger's password:
ranger

Still need it to read from the node list though.
__________________


Webinfractions.com
Think I'm wrong? You're probably right!

Reply With Quote
  #18  
Old October 12th, 2004, 02:41 AM
andyb1ack andyb1ack is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 60 andyb1ack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 14 sec
Reputation Power: 4
Hi StevenC,

Cool, that worked then.
I think you just needed that -n switch with the ssh command.
This prevents ssh from reading the whole of stdin in one go and should get your loop to work.
Can you please let me know what your original script does if you put the -n switch in the ssh command?

Cheers, Andy

Reply With Quote
  #19  
Old October 13th, 2004, 01:57 PM
StevenC's Avatar
StevenC StevenC is offline
PHP & Java Error Master
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2003
Location: My Computer
Posts: 1,218 StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 1 h 32 m 40 sec
Reputation Power: 15
It works like it should now, connecting to each node in the sequence.
In my original script, I'm trying to run various commands remotely to gather information about the system.
The output form those commands seem to be for the box I'm running the script from, and not from the box I connect to.

Here's a sample of the output:
Code:
Reading in node names from file...
username@lightning2's password:
lightning2
Connected to LIGHTNING2!
Node name   :  lx-dbsb-ts
OS Name     :  Linux
OS Version  :  2.4.9-e.43smp
IP Address  :  (147.179.164.102)
Memory      :  3835 MB
CPU Count   :  4
Waiting 2 before reconnect...
username@ranger's password:
ranger
Connected to RANGER!
Node name   :  lx-dbsb-ts
OS Name     :  Linux
OS Version  :  2.4.9-e.43smp
IP Address  :  (147.179.144.113)
Memory      :  3835 MB
CPU Count   :  4

Any ideas?

Reply With Quote
  #20  
Old October 13th, 2004, 10:19 PM
Perderabo Perderabo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 121 Perderabo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 54 sec
Reputation Power: 5
You have code like this:
Code:
        ssh -l username $linevar
        echo "Connected to $linevar!"

        ### Obtain system information ###

        node=$(uname -n | tr '[A-Z]' '[a-z]')
        os=$(uname)


It seems like you expect some of those statements to be executed on the remote system. Which ones? I certainly can't tell. I'm guessing that by the time you get to:
echo "OS Name : $os" #>> ../data/node_details.txt

you expect to magically be back on the originating system so you can collect data into a common local file. You can't simply put a bunch of code after a ssh command and expect the system to figure out what to execute where. Each line will be executed by the local shell on the local system.

Doing what you want will be very hard. The easiest way to approach this would be to write a script called "displaydata" and install it on each remote system. Then run it with
ssh -n user@NODE /some/path/displaydata
and capture the output of that.

Reply With Quote
  #21  
Old October 14th, 2004, 12:10 PM
StevenC's Avatar
StevenC StevenC is offline
PHP & Java Error Master
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2003
Location: My Computer
Posts: 1,218 StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 1 h 32 m 40 sec
Reputation Power: 15
So using ssh doesn't actually connect me to the remote machine?

I would assume once connected to the remote machine commands executed would be done so on the remote box.

I'll handle capturing the output at a later time.

As per your suggestion of having a script on each box, theres ~400+ nodes to execute those commands on, so I can't exactly sit around and upload each to each box.

Reply With Quote
  #22  
Old October 14th, 2004, 02:27 PM
Perderabo Perderabo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 121 Perderabo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 54 sec
Reputation Power: 5
So you want to create a file on each of the the 400 machines? Not one super big local file? Well that is easy. You can use a "here document".

ssh -l username $linevar << EOF
uname -a # command to be executed remotely
something_else #commandto be executed remotely
EOF

You never said what shell you were using. Read the docs for your shell with respect to "here documents". Basicly all of the lines between the ssh and the final "EOF" are collected and become input to the ssh command. That will cause them to be executed in a remote shell.

Also, if you have ssh, you probably have scp. It should take you 5 minutes to write a script to scp a scriptfile to 400 hosts. And maybe another 10 minutes to run it. And the script that you're writing could scp the file to /tmp on a host, run it, collect the results, and move on to the next host.

Reply With Quote
  #23  
Old October 15th, 2004, 07:36 AM
andyb1ack andyb1ack is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 60 andyb1ack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 14 sec
Reputation Power: 4
Hi StevenC,

I agree with Perderabo. If a command is getting to difficult to perform on each node via
ssh ... <command>
then I would create a script and copy it to all the nodes and then run it via
ssh ... <script>

If you have a look at my post on
"September 24th, 2004, 09:57 AM"
it'll probably make more sense to you now.

We've not got ssh and scp yet at my site so I've been using ftp to copy the files about.

Cheers, Andy

Reply With Quote
  #24  
Old October 15th, 2004, 11:18 AM
StevenC's Avatar
StevenC StevenC is offline
PHP & Java Error Master
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2003
Location: My Computer
Posts: 1,218 StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 1 h 32 m 40 sec
Reputation Power: 15
The script'll probably be running on korn shell, though there's a possibility it'll be on bash. (I could also run it as bash if needed).

Edit:

When I run the ssh command with here docs, it seems to execute the commands before attempting to connect to the remote box.
Here's the output:
Code:
usc_main: oslevel: command not found
ping: invalid option -- a
Usage: ping [-LRUbdfnqrvV] [-c count] [-i interval] [-w wait]
        [-p pattern] [-s packetsize] [-t ttl] [-I interface address]
        [ -T timestamp option ] [ -Q tos ] host
lsattr: invalid option -- E
Usage: lsattr [-RVadlv] [files...]
usc_main: lscfg: command not found
ping: invalid option -- a
Usage: ping [-LRUbdfnqrvV] [-c count] [-i interval] [-w wait]
        [-p pattern] [-s packetsize] [-t ttl] [-I interface address]
        [ -T timestamp option ] [ -Q tos ] host
usc_main: /usr/sbin/prtconf: No such file or directory
usc_main: /usr/sbin/psrinfo: No such file or directory
username@lightning2's password:
lightning2
usc_main: oslevel: command not found
ping: invalid option -- a
Usage: ping [-LRUbdfnqrvV] [-c count] [-i interval] [-w wait]
        [-p pattern] [-s packetsize] [-t ttl] [-I interface address]
        [ -T timestamp option ] [ -Q tos ] host
lsattr: invalid option -- E
Usage: lsattr [-RVadlv] [files...]
usc_main: lscfg: command not found
ping: invalid option -- a
Usage: ping [-LRUbdfnqrvV] [-c count] [-i interval] [-w wait]
        [-p pattern] [-s packetsize] [-t ttl] [-I interface address]
        [ -T timestamp option ] [ -Q tos ] host
usc_main: /usr/sbin/prtconf: No such file or directory
usc_main: /usr/sbin/psrinfo: No such file or directory
username@ranger's password:
ranger

Last edited by StevenC : October 15th, 2004 at 12:11 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Shell scripting > Looping through the contents of a file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway