Bash expect problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash expect problem
# 1  
Old 08-28-2016
Bash expect problem

Hey there Smilie

I have a Bash Script and I'm trying to update Roundcube, but theres a user interactive line like:
Code:
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:

Code:
cd roundcubemail-1.2.1 >/dev/null 2>&1
expect -c 'bin/installto.sh /var/www/mail/rc >/dev/null 2>&1'
expect "Do you want to continue? (y/N)"
send "y"
interact
rm -r /root/roundcubemail-1.2.1/ >/dev/null 2>&1
[even more code]

But the result is smth like this:
Code:
invalid command name "bin/installto.sh"
    while executing
"bin/installto.sh /var/www/mail/rc >/dev/null 2>&1"
couldn't read file "Do you want to continue? (y/N)": no such file or directory
update.sh: line 104: send: command not found
update.sh: line 105: interact: command not found

Is there any way that the update can run without user interaction and returning to other commands (like rm -r /root/roundcubemail-1.2.1/)

best regards

Last edited by vbe; 08-28-2016 at 01:22 PM.. Reason: more code tags
# 2  
Old 08-28-2016
Unless bin is the next folder up from the current directory then I see an error here:-
Code:
 expect -c '/bin/installto.sh /var/www/mail/rc >/dev/null 2>&1'

# 3  
Old 08-28-2016
I've edited the script and still the same error:

Code:
if [ "$ROUNDCUBE_UPDATE" = '1' ]; then
        echo "${info} Update Roundcube" | awk '{ print strftime("[%H:%M:%S] |"), $0 }'
        cd ~/sources >/dev/null 2>&1
        wget https://github.com/roundcube/roundcubemail/releases/download/${ROUNDCUBE_VERSION}/roundcubemail-${ROUNDCUBE_VERSION}-complete.tar.gz >/dev/null 2>&1
        tar xfvz roundcubemail-${ROUNDCUBE_VERSION}-complete.tar.gz >/dev/null 2>&1
        cd roundcubemail-${ROUNDCUBE_VERSION} >/dev/null 2>&1
        expect -c '/bin/installto.sh /var/www/mail/rc'
        expect "Do you want to continue? (y/N)"
        send "y"
        interact
        rm -r /root/sources/roundcubemail-${ROUNDCUBE_VERSION}/  >/dev/null 2>&1
        rm -f /root/sources/roundcubemail-${ROUNDCUBE_VERSION}-complete.tar.gz/ >/dev/null 2>&1
        echo "${ok} Finished: Roundcube Update" | awk '{ print strftime("[%H:%M:%S] |"), $0 }'
fi

version is 1.2.1 and from a config file

After running the script there are these folders:
/sources/roundcubemail-1.2.1/bin/installto.sh

I'm not sure if expect "Do you want to continue? (y/N)" is enough, since the output from the installto.sh is:
Upgrading from 1.1.3. Do you want to continue? (y/N)

installto.sh isnt a "real" sh, its a php i guess:
#!/usr/bin/env php
<?php [...]

if this information does matters

Last edited by Aeris; 08-28-2016 at 01:49 PM..
# 4  
Old 08-28-2016
I'm afraid expect doesn't work that way. It would execute a command given in the -c option, then execute an expect script (just expect commands) provided either in a file, given by the -f option, or from stdin.

You seem to mix shell and expect commands.

It looks like you want to provide commands via stdin. But, what you do is execute four commands from the shell: expect, expect (again), send, and interact. The latter two will almost certainly be rejected by the shell, with an error message.
Try to put the expect commands into a file, or use "here documents" in the shell
# 5  
Old 08-28-2016
Quote:
Originally Posted by RudiC
I'm afraid expect doesn't work that way. It would execute a command given in the -c option, then execute an expect script (just expect commands) provided either in a file, given by the -f option, or from stdin.

You seem to mix shell and expect commands.

It looks like you want to provide commands via stdin. But, what you do is execute four commands from the shell: expect, expect (again), send, and interact. The latter two will almost certainly be rejected by the shell, with an error message.
Try to put the expect commands into a file, or use "here documents" in the shell
Edit:
Code:
yes | bin/installto.sh /var/www/mail/rc

seems to work, but can i also write:
Code:
yes | bin/installto.sh /var/www/mail/rc >/dev/null 2>&1


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 08-28-2016 at 02:51 PM.. Reason: Added CODE tags.
# 6  
Old 08-28-2016
In principle, yes; but isn't it always helpful to have a log of what happened? Redirect to a file, and, when happy with the result, remove that file.
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cisco, 2 ssh logins for expect /bash

HI all i need to connect to about 900 cisco routers and switch to do some configs changes. the issue i am having is that half the devices have one set of username and password and the other half have another username and password. From expect or bash script i can ssh into a device and make... (0 Replies)
Discussion started by: quintin
0 Replies

2. 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

3. 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

4. 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

5. Shell Programming and Scripting

Problems with expect and sftp in bash

I'm having trouble with some automated sftp pulls. I'm using expect inside bash scripts and spawning SFTP. Some times the expect seems bog down. I have tried to put sleeps in my code to give everything time to work before I move on to next step but I till continue to get issues. For example when... (2 Replies)
Discussion started by: gosteen
2 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

Expect not working inside my Bash script

I am trying to execute expect command inside by small bash script to login into servers using key authentication method. My script is as follows: #!/bin/bash HOST=$1 /usr/bin/expect -c " spawn ssh -i /root/.ssh/id_rsa root@$HOST expect -exact "Enter... (3 Replies)
Discussion started by: John Wilson
3 Replies

8. Shell Programming and Scripting

Expect in bash to get the return value

cat test.sh #!/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/ ... (1 Reply)
Discussion started by: yanglei_fage
1 Replies

9. 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

10. 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
Login or Register to Ask a Question