Expect in bash to get the return value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expect in bash to get the return value
# 1  
Old 11-19-2013
Expect in bash to get the return value

cat test.sh

Code:
#!/bin/sh

expect <<- EOF
set timeout 5
spawn ssh -o StrictHostKeyChecking=no lyang0@128.224.178.245 -C mkdir -p /tmp
expect {
        "Password:"     {send "root\r"}
        }

        spawn scp -o StrictHostKeyChecking=no /tmp/1 lyang0@128.224.178.245:/tmp/
        expect {
                "password:"     { exit 8 }
                timeout {  exit 2 }
                }

EOF
((((( get the above expect part's return value))))

if want if 8 echo pass if 2 failed in the bash (not expect)

how to get the expect part's return value in test.sh ?

Last edited by yanglei_fage; 11-19-2013 at 10:44 PM..
# 2  
Old 11-26-2013
$? is any process's exit/return code in sh/ksh/bash.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Bash script + expect

im very happy to back for this forum I have servers with alias of double dns extentions: sample: servera.test.com servera.test1.com serverb.test.com serverb.test1.com I need to login to that severs and executing the set of commands if test.com failed then try to login via... (0 Replies)
Discussion started by: prakash0106
0 Replies

2. UNIX for Beginners Questions & Answers

Expect return code

Hello everyone Can some help me with understand return code in expect #!/usr/bin/expect set timeout 1 set SRV set user set pw spawn ssh $user@$SRV expect { "(yes/no)? " { send "yes\r" ; exp_continue } "assword: " { send "$pw\r" ; exp_continue } eof }... (2 Replies)
Discussion started by: vikus
2 Replies

3. Shell Programming and Scripting

Bash expect problem

Hey there :) I have a Bash Script and I'm trying to update Roundcube, but theres a user interactive line like: bin/installto.sh /var/www/mail/rc Upgrading from 1.1.3. Do you want to continue? (y/N) I'm trying to avoid this user interaction like this: cd roundcubemail-1.2.1 >/dev/null... (5 Replies)
Discussion started by: Aeris
5 Replies

4. UNIX for Beginners Questions & Answers

Expect in Bash - and then compare md5sum

I'm running on a staging server. I will need to use expect and I think ssh or scp to the other boxes. I need to see something like this....Enter:Host 1 Enter:Host 2 Enter full directory path to compare: example /apps/acd/jboss-customer1/ Enter User Id: Enter Password: ( Assumes... (6 Replies)
Discussion started by: xgringo
6 Replies

5. Shell Programming and Scripting

Bash script with expect

Dear all Hi I want use expect in bash so that we can not use these with each other /bin/bash. With. /usr/bin/expect How can use these with on script or how can call a script from other script #!/bin/bash clear echo "================================== " echo "Enter your Esxi IP"... (3 Replies)
Discussion started by: Baber
3 Replies

6. Shell Programming and Scripting

Expect - bash and variables

I was wondering if anyone could provide some assistance. I trying to run an expect script within bash and get the results of a variable called RESULT. I Have tried a few things but none of them have worked. I know that the child process (the expect script) in this instance cannot set a variable... (6 Replies)
Discussion started by: ylafont
6 Replies

7. Shell Programming and Scripting

OSX bash & expect

I have a script that must perform a 'sudo' operation on each of a number of hosts. I'm trying to get expect working so I only have to enter it once, and have run into a couple of issues. First, several examples suggest to use: /usr/bin/expect <<EOD spawn ssh -t $host /usr/bin/sudo -v... (7 Replies)
Discussion started by: jnojr
7 Replies

8. Shell Programming and Scripting

expect in bash script

Hi, I'm writing a shell script that calls a few commands that prompt the user for two simple yes/no questions. if the answers are consistent (the first is a yes, the second is a no), what would my expect script look like? Google is only giving me answers for scripts where I telnet or ssh. right now... (3 Replies)
Discussion started by: js741
3 Replies

9. Shell Programming and Scripting

How to return value from expect script?

Hi there. There is a shell script: #!/bin/bash ARGS=`(grep -i $1 old.txt || grep -i $1 new.txt) |awk 'BEGIN {FS=","}{print "\x27" $5 "\x27"}' | tr "\n" " "` /usr/bin/expect -- << EXPECTEND spawn -noecho myssh myhost.localnet log_user 0 expect root log_user 1 send "/home/one.pl... (4 Replies)
Discussion started by: urello
4 Replies

10. Shell Programming and Scripting

Return name of running WM in bash?

While I am by habit comfortable with bash as a shell, from time to time, I find tiny reasons to believe it's a little dense. One of the things that proves it is: to date, I have not been able to get it to identify what WM it's running inside of or alongside of in an X11 kind of environment... (1 Reply)
Discussion started by: SilversleevesX
1 Replies
Login or Register to Ask a Question