Find the answer to your Linux question:
Results 1 to 4 of 4
Hi, I am very new to bash scripting and after trying many different things I came to realize I need help I need to come up with script to to ...
  1. #1
    Just Joined!
    Join Date
    Nov 2009
    Location
    Chicago
    Posts
    7

    Bash script to login via ssh

    Hi,

    I am very new to bash scripting and after trying many different things I came to realize I need help

    I need to come up with script to to the following:

    1) ssh -1 host -l uname
    2) wait for password and echo the password
    3) after successful login I need to run a command show int status which is a simple IOS command

    Any help will appreciated.

    Thank you.

  2. #2
    Linux Engineer Thrillhouse's Avatar
    Join Date
    Jun 2006
    Location
    Arlington, VA, USA
    Posts
    1,377
    SSH allows you to execute a command in the connection string, e.g.:
    Code:
    $ssh host -l username <your_command_here>
    See man ssh for more details. If you need the console to wait before quitting in order to read the output:
    Code:
    $ssh host -l username <your_command_here> && sleep 3

  3. #3
    Just Joined!
    Join Date
    Nov 2009
    Location
    Chicago
    Posts
    7
    Thanks for you post.

    I need to login to a managed network switch first and then send a sequence of commands.

    I tried you suggestion with command && sleep 3 && command2 but this will execute commands that are BASH not ios as I am logging in to the switch.

    Any other ideas?

    Thank you.

  4. #4
    Just Joined!
    Join Date
    Nov 2009
    Location
    Chicago
    Posts
    7
    This solved my problem:

    ssh -1 host -l --pw kk >> /EOF

    cmd1
    cmd2
    cmd3

    EOF

    cmdx executes sequentially.

    Thanks everyone.

Posting Permissions

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