Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-19-2008, 03:38 PM   PM User | #1
timgolding
Senior Coder

 
timgolding's Avatar
 
Join Date: Aug 2006
Location: Southampton
Posts: 1,460
Thanks: 89
Thanked 110 Times in 109 Posts
timgolding is on a distinguished road
shell_exec and expect

im trying to get my php script to run expect like so....

PHP Code:
if($_GET["action"]=="reconstruct" && isset($_POST["username"]))
{

   if(
array_key_exists($_POST["username"],$names))    
   {
        
$string shell_exec("expect /home/scripts/reconstruct_mailbox.sh ".$_POST["username"]);  
        echo 
$string;
    }
    else
        exit;

here is a copy of the reconstruct_mailbox.sh

Code:
#! /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
Quote:
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?
__________________
You can not say you know how to do something, until you can teach it to someone else.
timgolding is offline   Reply With Quote
Old 12-19-2008, 04:11 PM   PM User | #2
tosbourn
Regular Coder

 
Join Date: Aug 2008
Location: Northern Ireland
Posts: 167
Thanks: 12
Thanked 6 Times in 6 Posts
tosbourn is on a distinguished road
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.
tosbourn is offline   Reply With Quote
Old 12-19-2008, 08:34 PM   PM User | #3
timgolding
Senior Coder

 
timgolding's Avatar
 
Join Date: Aug 2006
Location: Southampton
Posts: 1,460
Thanks: 89
Thanked 110 Times in 109 Posts
timgolding is on a distinguished road
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
__________________
You can not say you know how to do something, until you can teach it to someone else.
timgolding is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:21 PM.


Advertisement
Log in to turn off these ads.