Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

My target is to create the /var/tmp/add_user.bash script from /var/tmp/create_script_add_user.bash script and run the expect script (add_user.bash) from create_script_add_user.bash script.

The problem is that when I run the script add_user.bash from create_script_add_user.bash, then expect gets stuck on the question:

      Proceed? n) 

It looks like expect can't see the question from standard output. But when I run the script /var/tmp/add_user.bash, then it works fine.

Why can't expect run from the other script? And how to solve this issue?

Contents of /var/tmp/create_script_add_user.bash

   #!/bin/bash


   echo '#!/bin/bash


   add_user=`cat << EOF
   set timeout -1
   spawn /var/tmp/add_user.bash user_name=OBAMA
   expect n)   { send "yes\r" }
   expect eof
   EOF`

    /usr/local/bin/expect -c  "$add_user"

    '> /var/tmp/add_user.bash

    chmod +x /var/tmp/add_user.bash

    #need sleep for 5 seconds
    ( sleep 5 ; /var/tmp/add_user.bash ) &

Contents of /var/tmp/add_user.bash

 #!/bin/bash

 add_user=`cat << EOF
 set timeout -1
 spawn /var/tmp/add_user.bash user_name=OBAMA
 expect n)   { send "yes\r" }
 expect eof
 EOF`

 /usr/local/bin/expect -c  "$add_user"
share|improve this question
    
thx Vonbrand - did you think it will be better to migrate my question to stack-overflow ? –  yael Apr 3 '13 at 13:56
    
Also asked on serverfault –  glenn jackman Apr 3 '13 at 20:43
    
hi gilles can you consider to deliver my question to stackoverflow –  yael Apr 4 '13 at 6:45

1 Answer 1

up vote 1 down vote accepted

I find the solution for the problem

need to run the /var/tmp/add_user.bash without the process " & "

example

       #need sleep for 5 seconds

       sleep 5

       source /var/tmp/add_user.bash

now expect get the "n)" string and send "y" as answer

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.