|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#16
|
|||
|
|||
|
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
|
|
#17
|
||||
|
||||
|
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. |
|
#18
|
|||
|
|||
|
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 |
|
#19
|
||||
|
||||
|
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? |
|
#20
|
|||
|
|||
|
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. |
|
#21
|
||||
|
||||
|
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. |
|
#22
|
|||
|
|||
|
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. |
|
#23
|
|||
|
|||
|
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 |
|
#24
|
||||
|
||||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Shell scripting > Looping through the contents of a file |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|