shell script expect and spawn commands

Rahul surya

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.

Nahuel Fouilleul

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Passing values that the commands in a shell script are going to expect

Bash script to spawn and execute commands

spawn: How to pass arguments to spawn within an expect script?

Expect script to run shell command

A expect script with multiple shell statements

Shell script and sed commands

Commands not found in shell script

Expect script reading commands from file

Sending commands via SSH with expect script

How to make an expect script to input commands into GDB?

How to execute sudo commands with Expect & send commands in bash script?

Illegal Characters in Password in Expect / Shell Script

shell script connect three commands

Multiple Spawn/expect issue

Perl Expect spawn limit

Expect script embedded in shell: how to specify value defined in remote shell?

Calling bash shell script from expect script fails : "no such file or directory"

Running shell script with NSTask causes posix_spawn error

Expect script not recognizing "--MORE--", not running any commands after that

Problem with sending commands to mikrotik through telnet using expect script

Expect not waiting for prompt - script stops without sending other commands

Expect script not sending commands after successful ssh login

Expect - Spawn exiting after sometime

How to spawn from a variable in Expect

commands after read in shell script gives error

How to combine exec commands in shell script

Shell commands not working when grouped in a bash script

Shell Script to do SSH followed by further commands

How to execute the vim commands through shell script