Results 1 to 3 of 3

Thread: Expect not working

  1. #1
    Join Date
    Apr 2007
    Location
    Harrisburg Illinois USA
    Beans
    9
    Distro
    Ubuntu 10.04 Lucid Lynx

    Expect not working

    I cannot get Expect to do my bidding, it refuses.
    Wise ones what seems to be my problem?
    Forgive my ignorance.

    Code:
    #!/usr/bin/expect -f
    
    set SERVER [lindex $argv 0]
    set PASSWORD [lindex $argv 1]
    set COMMAND [lindex $argv 2]
    set timeout -1
    spawn ssh $SERVER
    match_max 100000
    expect "*?assword*"
    send "$PASSWORD\r"
    send "\r"
    send "$COMMAND\r"
    send "exit\r"
    Yeilds
    Code:
    kyhx@kyhx-netbook:/media/sda1/complete$ ./expect.ssh "kyhx@192.168.1.38" "mwahahaha" "ls>didit"
    spawn ssh kyhx@192.168.1.38
    kyhx@192.168.1.38's password: kyhx@kyhx-netbook:/media/sda1/complete$

  2. #2
    Join Date
    Dec 2006
    Beans
    256

    Re: Expect not working

    It is unclear precisely what you are expecting (NPI), but perhaps the following might provide a nudge in the right direction:

    Code:
    #!/usr/bin/expect -f
    
    set SERVER [lindex $argv 0]
    set PASSWORD [lindex $argv 1]
    set COMMAND [lindex $argv 2]
    set timeout 1
    spawn ssh $SERVER
    expect "*?assword*"
    send "$PASSWORD\r"
    expect "*\$$" 
    send "$COMMAND\r"
    expect $
    "We visited sixty-six islands and landed eighty-one times, wading, swimming (to shore). Most of the people were friendly and delightful; only two arrows shot at us, and only one went near -- So much for savages!" - J.C. Patterson

  3. #3
    Join Date
    Apr 2007
    Location
    Harrisburg Illinois USA
    Beans
    9
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Expect not working

    Thanks for the reply.
    Sorry let me explain. I am trying to automate a process to connect to a computer through ssh and run a command. The command "ls>didit" is for testing purpose only.

    The little bit you gave me got me a little farther, the new output is...
    Code:
    kyhx@kyhx-netbook:/media/sda1/complete$ ./expect.ssh "kyhx@192.168.1.38" "mwahahahawhat" "ls>didit"
    spawn ssh kyhx@192.168.1.38
    kyhx@192.168.1.38's password: 
    Linux kyhx-media 2.6.32-25-generic #45-Ubuntu SMP Sat Oct 16 19:48:22 UTC 2010 i686 GNU/Linux
    Ubuntu 10.04.1 LTS
    
    Welcome to Ubuntu!
     * Documentation:  https://help.ubuntu.com/
    
    Last login: Sun Nov  7 18:19:37 2010 from kyhx-netbook.westell.com
    kyhx@kyhx-media:~$
    So now it is the expect is not being met before the command. I tried to use [expect "kyhx@kyhx-media:~$"] to no success. All that is left is to get the command to run; any idea?

    It is unclear precisely what you are expecting (NPI), but perhaps the following might provide a nudge in the right direction:
    Oh it was totally intended, and I applaud you for it.=D>

Tags for this Thread

Bookmarks

Posting Permissions

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