Find the answer to your Linux question:
Results 1 to 2 of 2
Hello I’m trying to write script that doing login to HP Switch and then automatic update the Firmware. My problem was when the switch uploaded the Firmware from the TFTP ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2012
    Posts
    21

    Expect command with with bash, faild to run it.


    Hello

    I’m trying to write script that doing login to HP Switch and then automatic update the Firmware.
    My problem was when the switch uploaded the Firmware from the TFTP server, Expect always jumping to the other line and cannot wait for the upload to be done.
    I resolve it with “interact -o nobuffer” , its works ok, but now I want to be able to mix it with bash script, so the user will write the ip of the switch the with “read” I will put it in variable $ , the will do telnet to $ip.

    This is the original script

    #!/usr/bin/expect

    set prompt ">|#|\\\$"

    spawn telnet "10.0.0.50"
    expect "Username:"
    send "root\r";
    expect "Password:"
    send "xxxxx\r";
    interact -o -nobuffer -re $prompt return
    send "configure\r";

    interact -o -nobuffer -re $prompt return
    send "copy tftp flash 10.0.0.2 Y_11_35.swi\r\y";

    interact -o -nobuffer -re $prompt return
    send "wr me\r";

    interact -o -nobuffer -re $prompt return
    send "reload\r";
    expect "#";
    send "reload\r\y";

    exit


    this script working fine, but now I want to do something like that and I got error messages:


    #!/bin/bash

    echo "enter switch IP"
    read ip

    /usr/bin/expect -d <<EOF
    set prompt ">|#|\\\$"
    spawn telnet "$ip"
    expect "Username:"
    send "root\r";
    expect "Password:"
    send "XXXXX\r";
    expect "#";
    send "configure\r";

    expect $prompt
    send "copy tftp flash 10.0.0.2 Y_11_35.swi\r\y";

    interact -o -nobuffer -re $prompt return
    send "wr me\r";

    interact -o -nobuffer -re $prompt return
    send "reload\r";
    expect "#";
    send "reload\r\y";
    EOF
    exit




    And this is the error message:

    expect: timed out
    send: sending "copy tftp flash 10.0.0.2 Y_11_35.swi\ry" to { exp6 }
    defining key return, action interpreter
    interact: received eof from spawn_id exp0
    write() failed to write anything - will sleep(1) and retry...
    send: sending "wr me\r" to { exp6 }
    defining key return, action interpreter
    interact: spawn id exp0 not open
    while executing
    "interact -o -nobuffer -re return"
    write() failed to write anything - will sleep(1) and retry...


    from some reason, when there is #!/bin/bash on the header instead of #!/usr/bin/expect
    the script canot recognize the "interact no buffer" command.

    Do you have any suggestion?

    Thanks a lot!

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    try getting the password from user input "natively" within Expect. try variations on the first two answers at this Stackoverflow thread.

Posting Permissions

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