Find the answer to your Linux question:
Results 1 to 8 of 8
Hello! We use a SecureCRT .vbs script to automate logging into multiple boxes, however, I'd like to have something run in Linux vs. our emulator. Below is my objective: Our ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2014
    Posts
    4

    Lightbulb need script logging into multiple boxes and executing commands.


    Hello! We use a SecureCRT .vbs script to automate logging into multiple boxes, however, I'd like to have something run in Linux vs. our emulator. Below is my objective:

    Our current .vbs script will look at an IP list .txt file on our PC, then login to each IP within the .txt, and execute the following:

    Code:
    ssh router1 at [IP Address]
    su - root     # We get prompted for PW.
    su - secadmin2    # We do not get prompted for PW.
    cd .ssh
    cp authorized_keys authorized_keys_bkup
    cat /app2/.ssh/Vkey >> authorized_keys
    exit
    exit
    cd .ssh
    cp Vkey Vkey.orig
    cat Vkey >> authorized_keys
    rm /app2/.ssh/Vkey
    exit
    Again, the script must prompt for root password (only once since all root PW's will be the same), and loop commands above for all IP's found on file. Can anyone help with this? Your assistance and cooperation is truly appreciated!

  2. #2
    Linux Guru
    Join Date
    Dec 2013
    Location
    Victoria, B.C. Canada
    Posts
    1,650
    Something like this might work for you:
    Code:
    #!/bin/bash
    
    read -s -p "Enter Password: " pass
    for each in addr1 addr2 addr3
    do
            sshpass -p $pass ssh root@$each << EOT
                    su - secadmin2    # We do not get prompted for PW.
                    cd .ssh
                    cp authorized_keys authorized_keys_bkup
                    cat /app2/.ssh/Vkey >> authorized_keys
                    exit
                    cd .ssh
                    cp Vkey Vkey.orig
                    cat Vkey >> authorized_keys
                    rm /app2/.ssh/Vkey
                    exit
    EOT
    done

  3. #3
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,769
    Related note, I love Python Fabric for stuffs like this: They make life easier for managing lot of nodes.

    Fabric: a System Administrator's Best Friend | Linux Journal

    Fabric ? Fabric 1.8.2 documentation
    First they ignore you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -----
    FOSS India Award winning ext3fs Undelete tool www.giis.co.in. Online Linux Terminal http://www.webminal.org

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Feb 2014
    Posts
    4
    Thanks for the assist Greg! I kicked it off and received the following output, is it possible the box im working on does not have sshpass feature installed?

    root> ./gregm_script
    Enter Password: ./gregm_script: line 6: sshpass: command not found
    ./gregm_script: line 6: sshpass: command not found
    ./gregm_script: line 6: sshpass: command not found

  6. #5
    Just Joined!
    Join Date
    Feb 2014
    Posts
    4
    Thanks for the feedback Lakshmipathi and Gregm! I greatly appreciate your support! I know VBA, but not Linux, however, I'm a determined learner!.....I will learn!!! Your feedback is greatly appreciated!!

  7. #6
    Linux Guru
    Join Date
    Dec 2013
    Location
    Victoria, B.C. Canada
    Posts
    1,650
    Quote Originally Posted by birdboyee View Post
    Thanks for the assist Greg! I kicked it off and received the following output, is it possible the box im working on does not have sshpass feature installed?

    root> ./gregm_script
    Enter Password: ./gregm_script: line 6: sshpass: command not found
    ./gregm_script: line 6: sshpass: command not found
    ./gregm_script: line 6: sshpass: command not found
    Yes. It will probably need to be installed.

  8. #7
    Just Joined!
    Join Date
    Feb 2014
    Posts
    4
    Quote Originally Posted by gregm View Post
    Yes. It will probably need to be installed.
    Greg, I just found out were not allowed to install that feature. Is there another option vs sshpass function?

  9. #8
    Linux Guru
    Join Date
    Dec 2013
    Location
    Victoria, B.C. Canada
    Posts
    1,650
    You can look into ssh-keygen and password free login. There's a lot of examples on the net. Here's one: SSH Passwordless Login Using SSH Keygen in 5 Easy Steps

Posting Permissions

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