Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts

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

  • #2
    Regular Coder
    Join Date
    Aug 2008
    Location
    Northern Ireland
    Posts
    167
    Thanks
    12
    Thanked 6 Times in 6 Posts
    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.

  • #3
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •