Question

I have to pass a path at runtime as the abc.sh script will prompt for it .. I am trying following expect script to accomplish this,

#!/usr/bin/expect -f
set force_conservative 0  
if {$force_conservative} {
    set send_slow {1 .1}
    proc send {ignore arg} {
        sleep .1
        exp_send -s -- $arg
    }
}
spawn abc.sh
match_max 100000
expect -exact "Please enter path : "
send -- $path
expect -exact "\r
expect eof

Need your help – how I can pass $path values at run time calling like this ?

expect script.exp $path 

Thanks,

Was it helpful?

Solution

Expect Answer

Use send -- $argv in your expect script because $argv holds the command line arguments.

As an example, I've this handy expect script that interacts with ssh commands when admins stupidly disable public key authentication :

#!/usr/bin/expect -f
set timeout -1
set send_human {.6 .1 1.6 .1}
eval spawn $argv
match_max 100000
expect {
   -re "LOGIN@(\[0-9A-Za-z_\\-\\.\]+)'s password: "
    { sleep 0.6 ; send -- "PASSWORD" ; sleep 0.1 }
interact

Use constructs like [lrange $argv 0 $argc] if you need only part of the $argv

Perl Answer

Use system 'script.exp' $path to call script.exp from a perl script, assuming use chmod, etc., roughly like DeVadder said sans the quotes. Or use exec if your perl script wishes to terminate. Run man perlfunc to read about perl commands.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top