Ignore special characters in bash/expect script

Discussion in 'Command Line' started by meirh, Jan 3, 2013.

  1. meirh

    meirh New Member

    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi all, first of all, great forum, i have reading here a lot :)

    My question:
    I'm trying to write script that part of is job is to do telnet session to switch with expect commands.
    everything is ok except the password issu, my switches password is $toor, and $ is variable character, to resolve it, im writing it like that:
    $\toor, the problem is in expect "\t" is also special characters :~, you know \t \r \n those are special characters in expect.
    i tried 1000 of variation to how to write it right, i have tried $\toor , $\\toor , \$toor , \$\toor and other option but nothing have worked..

    does anyone are know how to resolve it?

    thats the command:
    /usr/bin/expect -d <<EOF > cdp.txt

    spawn telnet $switchip ;
    expect "Username:" ;
    send "root\r" ;
    expect "Password" ;
    send "$toor\r" ;
    expect "#" ;
    send "sh cdp neighbors detail $portnumber \r"
    expect "#"
    send "logout\n" ;
    EOF



    Thank you vry much, i have tried any possible variation, please help :)
  2. old_bolvan

    old_bolvan New Member

    Messages:
    15
    Likes Received:
    3
    Trophy Points:
    3
    Try "\\\$toor\\r"
    meirh likes this.
  3. meirh

    meirh New Member

    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0

    Work lile a dream! thanks a lot!!

Share This Page