Results 1 to 6 of 6

Thread: expect in a useful way?

  1. #1
    Join Date
    Jan 2009
    Location
    Denmark
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    expect in a useful way?

    So i am wondering. What is expect designed to do? Specifics please.

    I have no problems with it, logging into a remote system, or downloading files from a remote site.
    But when i try to edit something on a remote system, like creating a file. Nothing.

    Example Note $Amount equals a decimal value with no colons or anything.
    Code:
    /usr/bin/expect - << EndMark
    set timeout 1
    exp_internal 1
    spawn /usr/bin/ssh -f root@ip "/bin/ls /path/ |/bin/grep X_ |/usr/bin/head -n $Amount > /path/test"
    sleep 1
    expect "root@ip's password:"
    sleep 1
    send "password\r"
    sleep 1
    EndMark
    But it docent create the file at the remote site.
    This is the output i get

    Code:
    spawn /usr/bin/ssh -f root@ip /bin/ls /path/ |/bin/grep X_ |/usr/bin/head -n 5 > /path/test
    parent: waiting for sync byte
    parent: telling child to go ahead
    parent: now unsynchronized from child
    spawn: returns {4060}
    
    expect: does "" (spawn_id exp4) match glob pattern "root@ip's password:"? no
    root@ip's password: 
    expect: does "root@ip's password: " (spawn_id exp4) match glob pattern "root@ip's password:"? yes
    expect: set expect_out(0,string) "root@ip's password:"
    expect: set expect_out(spawn_id) "exp4"
    expect: set expect_out(buffer) "root@ip's password:"
    send: sending "password\r" to { exp4 }
    Why cant it run commands in expect i can run by hand?
    Also is their any up-to-date useful expect guides?

    Kind regards.

  2. #2
    Join Date
    Apr 2011
    Location
    La La Land
    Beans
    221

    Re: expect in a useful way?

    I don't have much experience with this, but it looks like it is trying to match a blank object "" (I don't know where it is coming from) with another form.

  3. #3
    Join Date
    Jan 2006
    Beans
    Hidden!
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: expect in a useful way?

    you are using expect wrong ... why on earth are you sticking everything you want to do into the ssh command? why not do it the way it was meant to be used?

    1. log in
    2. do stuff you need
    3. log out
    I am infallible, you should know that by now.
    "My favorite language is call STAR. It's extremely concise. It has exactly one verb '*', which does exactly what I want at the moment." --Larry Wall
    (02:15:31 PM) ***TimToady and snake oil go way back...
    42 lines of Perl - SHI - Home Site

  4. #4
    hakermania's Avatar
    hakermania is offline Τώρα ξέρεις τι γράφω εδώ!
    Join Date
    Aug 2009
    Location
    Greece
    Beans
    1,705
    Distro
    Ubuntu Development Release

    Re: expect in a useful way?

    Example usage of expect for updating this file: http://wall-changer.sourceforge.net/screenshots.html
    (part of the code that contains expect)
    Code:
    #!/bin/bash
    /usr/bin/expect - << EndMark
    set timeout -1
    
    spawn sftp username,wall-changer@web.sourceforge.net
    expect "username,wall-changer@web.sourceforge.net's password: "
    send "passwd\r"
    expect "Connected to web.sourceforge.net."
    send "cd htdocs\r"
    expect "sftp>"
    send "put screenshots.html\r"
    sleep 5
    EndMark
    exit

  5. #5
    Join Date
    Jan 2009
    Location
    Denmark
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: expect in a useful way?

    Quote Originally Posted by slavik View Post
    you are using expect wrong ...
    So what is the correct way?

    shouldn't expect be able to run the ssh -f user@ip "command" command?
    If no, why?

    And does anyone know why i get this
    I don't have much experience with this, but it looks like it is trying to match a blank object ""
    Last edited by Drenriza; December 13th, 2011 at 08:54 AM.

  6. #6
    Join Date
    Jan 2009
    Location
    Denmark
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: expect in a useful way?

    even if i do
    Code:
    #!/usr/bin/expect -f
    set timeout 60
    exp_internal 1
    
    spawn ssh root@ip
    sleep 1
    expect "root@ip's password:"
    sleep 1
    send "password\r"
    sleep 3
    send "/bin/ls /path/ |/bin/grep X_ |/usr/bin/head -n 5 > /path/test\r"
    exit
    it still docent work. Since the file is not created.
    So what am i doing wrong?

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
  •