Page 2 of 2 First 12
  • Jump to page:
    #16
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    60
    Rep Power
    14
    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
  2. #17
  3. PHP & Java Error Master
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    My Computer
    Posts
    1,219
    Rep Power
    0
    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.
  4. #18
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    60
    Rep Power
    14
    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
  6. #19
  7. PHP & Java Error Master
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    My Computer
    Posts
    1,219
    Rep Power
    0
    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?
  8. #20
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    121
    Rep Power
    14
    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.
  10. #21
  11. PHP & Java Error Master
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    My Computer
    Posts
    1,219
    Rep Power
    0
    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.
  12. #22
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    121
    Rep Power
    14
    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.
  14. #23
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    60
    Rep Power
    14
    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
  16. #24
  17. PHP & Java Error Master
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    My Computer
    Posts
    1,219
    Rep Power
    0
    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 01:11 PM.
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo