View Full Version : shell_exec and expect

12-19-2008, 04:38 PM
im trying to get my php script to run expect like so....

if($_GET["action"]=="reconstruct" && isset($_POST["username"]))

$string = shell_exec("expect /home/scripts/reconstruct_mailbox.sh ".$_POST["username"]);
echo $string;

here is a copy of the reconstruct_mailbox.sh

#! /usr/bin/expect -f
set username [lindex $argv 0]

spawn su timgolding
expect "Password:"
send "secret\r"

expect "timgolding$"
send "sudo su cyrus\r"

expect "Password:"
send "secret\r"

expect "cyrus$"
send "/usr/bin/cyrus/bin/reconstruct -r user/$username\r"

expect eof

the expect script is working i have tested it in terminal
Im not sure if the php will be working because it was only outputting this

spawn su timgolding Password: mail:/Volumes/Files/webmaster/cyrus-admin/web timgolding$ sudo su cyrus Password: mail:/Volumes/Files/webmaster/cyrus-admin/web cyrus$ /usr/bin/cyrus/bin/recon

its as though it only got to "recon" and did it finish that line of code. Its annoying it was the last line of coed in the script. How can i tell. Is there some sort of a timeout i can set to get it to wait a little longer for output? Any ideas?

12-19-2008, 05:11 PM
This may be of no help, but it isn't anything to do with the user that PHP is running as is it? If you access the PHP script from a browser it will run as a different user than if say you run it as a CRON or straight from the terminal.

12-19-2008, 09:34 PM
i know that why i the first command issued is su - change user :)
i know its doing most of the job i just wondered how i can tell if its finished