Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 28
Like Tree3Likes

Thread: Script to get info from multiple servers

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    26
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Post Script to get info from multiple servers

    Hi,

    I want to collect info from a no. of servers whether there grub.conf contain "elevator" parameter or not.

    What I want is


    Code:

    sudo cat /etc/grub.conf | grep -q "elevator=noop"; echo $?


    If output is "0", I want name of that host in a file called "present"
    if its not "0", I want that hostname in a file called "not-present".

    Now, Password less key authentication is something I can not do as of now. I am okay with specifying password in script.

    Can someone please help me achieving this?

  2. #2
    Senior Member Rahul.Patil's Avatar
    Join Date
    Feb 2012
    Location
    Mumbai india
    Posts
    447
    Thanks
    10
    Thanked 46 Times in 43 Posts
    Rep Power
    6

    Default

    Hi,

    Code:
    #!/bin/bash
    # store username:ip combo here separated by a whitespace
    _pair="root@192.168.250.30"
    GRUB="/boot/grub/grub.cfg"
    for e in $_pair
    do
                 # extract user and ips for each $e in $_pair
            IFS='@'
            set -- $e
            _user="$1"
            _ip="$2"
    
            sleep 2
            echo "Connecting to server '${_ip}' via SSH..."
            ssh ${_user}@${_ip} "if grep -q "elevator=noop" "$GRUB" >/dev/null; then
            echo "Present"
            else echo "not present"
            fi "
    done
    stunn3r likes this.
    Rahul Patil <http://www.linuxian.com>

  3. The Following 2 Users Say Thank You to Rahul.Patil For This Useful Post:

    jaysunn (29th October 2012), stunn3r (20th October 2012)

  4. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    26
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    Hey,

    Thanks a lot Rahul, That script is working perfectly for the purpose it was made.

    I experienced some problem while making best of it:

    I 've around 150 servers on which I want to run this, so it would be good if the script picks up the server name or Ip's from a different file.

    Also I don't want to give password every time, and as password less authentication is not present in my environment, I've to pass the password in script itself which really doesn't bother me, I can do that, Its not like I am entering root password. I'll do everything my my ID. I know it could be done through expect but I messed everything every time I tried using it.

    3rd thing, whenever I ssh a server it gives me following message(not always, sometimes)
    HTML Code:
    The authenticity of host '10.40.111.111' can't be established.
    RSA key fingerprint is e8:67:3b:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx.
    Are you sure you want to continue connecting (yes/no)?
    so it expect a yes, I've to bypass this too if it is asked.

  5. #4
    Senior Member Rahul.Patil's Avatar
    Join Date
    Feb 2012
    Location
    Mumbai india
    Posts
    447
    Thanks
    10
    Thanked 46 Times in 43 Posts
    Rep Power
    6

    Default

    Hi,

    Better and Secure is load keys on all servers.
    i don't know about expect but you can search on this forum you will find more link on the same , check this link
    Rahul Patil <http://www.linuxian.com>

  6. #5
    Junior Member
    Join Date
    Sep 2012
    Posts
    26
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    Quote Originally Posted by Rahul.Patil View Post
    Hi,

    Better and Secure is load keys on all servers.
    i don't know about expect but you can search on this forum you will find more link on the same , check this link
    Hmm .. Okay .. Can you tell me how to make your script to pick server names/ip's from a file ?

  7. #6
    Senior Member Rahul.Patil's Avatar
    Join Date
    Feb 2012
    Location
    Mumbai india
    Posts
    447
    Thanks
    10
    Thanked 46 Times in 43 Posts
    Rep Power
    6

    Default

    Quote Originally Posted by stunn3r View Post
    Hmm .. Okay .. Can you tell me how to make your script to pick server names/ip's from a file ?
    just do this

    _pair="$(cat /tmp/ip_list.txt)"

    and /tmp/ip_list.txt file should be as below
    user@192.168.1.10
    user@192.168.1.11
    user@192.168.1.13
    Rahul Patil <http://www.linuxian.com>

  8. #7
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,384
    Thanks
    17
    Thanked 755 Times in 496 Posts
    Rep Power
    10

    Default

    Quote Originally Posted by Rahul.Patil View Post
    _pair="$(cat /tmp/ip_list.txt)"
    Or use <
    Code:
    _pair="$(</tmp/ip_list.txt)
    Rahul.Patil likes this.
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


  9. The Following 2 Users Say Thank You to nixcraft For This Useful Post:

    jaysunn (29th October 2012), stunn3r (22nd October 2012)

  10. #8
    Junior Member
    Join Date
    Sep 2012
    Posts
    26
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    Quote Originally Posted by nixcraft View Post
    Or use <
    Code:
    _pair="$(</tmp/ip_list.txt)
    Thanks a lot sir .. It worked ..

    here it is:

    Code:
    #!/bin/bash
    
    
    GRUB="/etc/grub.conf"
    _pair="$(</home/wadhwaso/login.txt)"
    for e in $_pair
    do
                 # extract user and ips for each $e in $_pair
            IFS='@'
            set -- $e
            _user="$1"
            _ip="$2"
    
    
            sleep 2
            echo "Connecting to server '${_ip}' via SSH..."
            ssh ${_user}@${_ip} "if sudo grep -q "elevator=noop" "$GRUB" >/dev/null; then
            echo "Present"
            else echo "not present"
            fi "
    done
    Honestly, I never understood significance of "e" here and what is "IFS" .. I just started watching some videos about scripting, dont have mush idea about it. Could you please explain these things in the script

    Also I am trying to use expect in the script so that I dont have to give password. I'll post it here once I get it to work.

    Again, Thank You .

  11. #9
    Junior Member
    Join Date
    Sep 2012
    Posts
    26
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    One more question:

    what I want to do is instead of echo'ing "present" I want that {_ip} to go in a local file called "present" on the server from I am running the script and for "not present" I want that {_ip} to go in a local file called "not-present" on the server from I am running the script
    Last edited by stunn3r; 22nd October 2012 at 01:55 PM.

  12. #10
    Senior Member Rahul.Patil's Avatar
    Join Date
    Feb 2012
    Location
    Mumbai india
    Posts
    447
    Thanks
    10
    Thanked 46 Times in 43 Posts
    Rep Power
    6

    Default

    Quote Originally Posted by stunn3r View Post
    One more question:

    what I want to do is instead of echo'ing "present" I want that {_ip} to go in a local file called "present" on the server from I am running the script and for "not present" I want that {_ip} to go in a local file called "not-present" on the server from I am running the script
    You just need to use ${_ip} as below
    Code:
    echo "not present on ${_ip}"
    Rahul Patil <http://www.linuxian.com>

Page 1 of 3 1 2 3 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to run a script to multiple servers?
    By ashishvarshney in forum Shell scripting
    Replies: 3
    Last Post: 2nd February 2012, 02:45 PM
  2. Shell script to find a file in multiple unix servers.
    By redrock in forum Shell scripting
    Replies: 4
    Last Post: 27th April 2011, 06:02 PM
  3. script to rm files on multiple servers
    By steve_f60 in forum Shell scripting
    Replies: 1
    Last Post: 21st June 2008, 10:29 PM
  4. login into multiple servers thru script...
    By avcert1998 in forum Shell scripting
    Replies: 2
    Last Post: 17th March 2007, 03:29 AM
  5. Script to add users to multiple servers.
    By deepakhg in forum Shell scripting
    Replies: 0
    Last Post: 17th March 2007, 03:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41