Expect script problem

f t
2010-06-22
2013-05-02
  • f t

    f t - 2010-06-22

    I have a Python script calling a shellscript which in turn calls an expect script.  The Python script calls the shellscript using subprocess popen and passes a value thru stdin.  The shellscript reads the value and passes it along to the expect script.
    I am spawning mysql in the expect script.  If I run the Python program, the expect script fails.  Whereas if I run the shellscript
    from the command line, then I see the mysql prompt. 
    I would appreciate any help in figuring out where the problem is.
    I have included all the 3 scripts here for reference.

    Thanks.

    Python script with subprocess

    import subprocess
    print '\n===================In dummy.py=========================='
    proc = subprocess.Popen(,
                             shell=True,executable='/bin/bash',
                            stdin=subprocess.PIPE,
                            )
    proc.communicate('pass')

    Shellscript

    #!/bin/bash
    read pass
    echo "-------------In shell script : $pass ---------"
    ./exp $pass

    Expect

    #!/usr/bin/expect
    set mypass
    set mypass
    puts "====inexp=======$mypass================"

    spawn mysql -uroot -p
    #######################
    expect "Enter password: "
        send "pass\r"
    interact
    ===================================================================

     
  • Mostafa Tavakoli

    I found a command to directly scp my file to a host (C) via another host (B) from my computer. The command is in this form:

    scp -oProxyCommand="ssh -W %h:%p B" thefile C:destination

    I used it and it works good in command line. but when I want to write an expect script using this command, I got some errors. the script I've written is in this form:

    1
    2
    3
    4
    5
    6
    7
    #!/usr/bin/expect
    
    set arg1 [lindex $argv 0]
    
    spawn scp -oProxyCommand="ssh -W %h:%p B" ./$arg1 C:destination 
    
    interact
    

    and the error is:

    unknown option -- W
    W option works in command line but not in expect script. Can anybody tell me why?

     
    Last edit: Mostafa Tavakoli 2017-06-11

Log in to post a comment.