Find the answer to your Linux question:
Results 1 to 3 of 3
i'm planning to do an automatic distribution of a configuration to a router,i decided to use expect script,telnet,and tftp to do that so i came up with this script on ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2012
    Posts
    2

    copy configuration from tftp to router using expect


    i'm planning to do an automatic distribution of a configuration to a router,i decided to use expect script,telnet,and tftp to do that

    so i came up with this script on the internet and edit a few lines

    #!/usr/bin/expect

    ## TomDV
    ## hxxp://blog.****mbra.be/2010/02/expect-scripts-backup-cisco-config/]Using expect scripts to backup your Cisco configuration Penumbra

    # ---------------- configuration ---------------- #
    set device 192.168.0.100
    set tftp 192.168.0.200
    set user someuser
    set pass ultrasecret
    set config /tftpboot/config
    set position running-config
    set timeout 60

    # -------------- do not edit below -------------- #
    spawn telnet $device
    expect "Password:"
    send "$pass\n"
    expect ">"
    send "en\n"
    expect "Password:"
    send "$pass\n"

    send "copy tftp://$tftp/$config $posittion\n\n\n"
    expect "$tftp"
    send "\n"
    expect "$config"
    send "\n"
    expect "$position"
    send "\n"
    send "\n"
    send "exit\n"
    the script works fine for copying small configuration files,but when it's used to transfer a more complicated configuration the script failed,and on the router says "SYS-3-CONFIG_SYS_ERR failed to write"

    i'm guessing the problem here is because bigger configuration takes more time to transfer than smaller one,and the script sends "exit\n" before the transfer complete

    so is there any way to delay "exit\n" until the transfer completed?

    ps:sorry for the bad english
    --fathul--

  2. #2
    Just Joined!
    Join Date
    Jan 2012
    Posts
    21
    Hi

    Read my thread, it in few topics under you
    I did exactly what you want, just change the details to match your needs.

  3. #3
    Just Joined!
    Join Date
    Jul 2012
    Posts
    2
    hi meirh
    thanks for your reply, but i've already solved the problem
    the script fails because i didn't insert "expect #" so the script doesn't wait until the transfer completed,also i made some changes in time out variable to infinite by editing "set timeout -1"

    the end of the script should be like this

    expect "$position"
    send "\n"
    send "\n"
    expect "#"
    send "exit\n"

    regards
    --fathul

  4. $spacer_open
    $spacer_close

Posting Permissions

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