Rahul surya Rahul surya -4 years ago 119
Bash Question

shell script expect and spawn commands

Actually i am writing 2 scripts of

a.sh

#!/bin/sh

PASSPHRASE="PASS"
for i in 1 2
do
echo "say hii:"
done


another script of
b.sh

#!/usr/bin/expect -f

spawn ./a.sh
sleep 2
for {set x 1} {$x<3} {incr x} {
expect "say hii:"
send "hii\r"
sleep 10
interact
}

executing ./b.sh


so for the first time it is sending
say hii: "and we are sending hii"


for the second time it getting struck in say hii:


so i would like to send two times means how many time for loop is there.

Answer Source

a.sh finishes after writing say hii twice

#!/bin/sh

PASSPHRASE="PASS"
for i in 1 2
do
    echo "say hii:"
    IFS= read -r line && echo "$0 read: $line"
done

b.sh

#!/usr/bin/expect -f

spawn ./a.sh
sleep 2
for {set x 1} {$x<3} {incr x} {
    expect "say hii:"
    send "hii\r"
    sleep 1
}
interact
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download