Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

php with qmail and sh -c

Options
  • 02-03-2002 2:15am
    #1
    Closed Accounts Posts: 25


    Hey, I'm trying to get qmail to run a php shell script.


    I havent built the script yet, I'm just doing a few tests ... I seem to be able to run "hello world" scripts, and a few simple emailers / file writing scripts using the
    php file.php
    

    this executes the file and runs the code. I can also feed in arguments by using the argv[] array, and I can get it to take input, as in the phpbuilder article http://www.phpbuilder.com/columns/darrell20000319.php3

    My problem is that qmail runs the script through sh -c command

    so if my file is email.php, qmail executes the following:
    sh -c php email.php
    
    effectively feeding the email into the script using STDIN (standard input)

    The problem is that the scripts don't seem to do anything at all.. none of the functions execute, and actions that work fine when I execute them with just
    php email.php
    
    on its own ...

    I'm really stumped, but this is something I really want to get working....

    If I could just get an inkling as to why it's not executing the scripts...

    Thanks

    Paul


Comments

  • Closed Accounts Posts: 286 ✭✭Kev


    put a shebang line at the start of the script e.g. #!/usr/local/bin/php

    and then give the script execute permission, like chmod 711 script.php


  • Closed Accounts Posts: 25 pabcas


    Yeah .. I had all that done .. still wouldn't work ..

    I've resolved to using perl ...

    It will work, but I'm just not as confident about getting perl to do the things I want .. and it'll take a little longer.

    Oh well.


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    The shell thinks that "file.php" is part of your command. Try putting the command in quotes, and using the full path to PHP. Also, don't forget to append -q to the php command line, to kill off the automatic headers.
    sh -c "/path/to/php -q file.php"
    
    (You don't need the hash-bang-path in the file if you're executing it directly from the command line, neither do you need to set execute permissions on the file -- if you can execute php and you can read the file, you can execute the file. PHP just reads it in and evaluates it.)

    HTH,
    adam


  • Closed Accounts Posts: 25 pabcas


    I may try all these later, but I've got perl working, and it's taken my three days to even get it working.

    It's a beautiful script, that hopefully when I'm done will allow me to send email to an address, it'll parse the address and update the database accordingly with subject & message ...

    I've so far got the script to read the message, strip all the headers (hacked this of course), post into the database, and send a confirm email back.

    What I want it to do is read the post-*-*@blast.ie email address, and post to the proper site and table accordingly.

    Then I have to add some security . Which is always fun.

    Thanks for your help..


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    I've so far got the script to read the message, strip all the headers (hacked this of course)

    Heh, you could have pulled all that verbose from php-general, there's a function and/or class to do this in there for years. Or you could have used a section from phorummail, which comes bundled with Phorum. Spoilsport, eh?

    Errah, there's more pleasure in doing it yourself anyway. :)

    adam


  • Advertisement
  • Closed Accounts Posts: 25 pabcas


    actually no .. I'm good

    .. if you noticed the "hacked this of course" bit... All I did was took a script which did this, chopped off the rest of it, and started putting my own stuff in ...

    But I'll remember what you told me the next time.

    I feel like such a treasonous wretch getting perl to do my donkey work for me.

    ah well. I suppose I'm a dishonourable coder one way or another, after all, I work on my own....


  • Closed Accounts Posts: 25 pabcas


    while you're there, you wouldn't happen to know how to access global environment variables from inside what seems to be a perl sub?

    If I was in php and needed $DOCUMENT_ROOT I'd just go

    global $DOCUMENT_ROOT;

    but perl seems to use <HOME>

    or something to that effect .. can't for the life of me get it to work.

    Although I'm something of a not give upper me... so I may get it before you reply. Hopefully not though.


  • Closed Accounts Posts: 25 pabcas


    Ok, she's done.

    I did it in perl, wasn't too bad learning the ins and outs, and the debug from the command prompt is actually more helpful than the php one....

    It's an email intercept script, which takes an email, the first line of which is the administrators username and password, checks the database for the username and md5'd password, chops the username and password of the message body, updates the database, and sends a confirm email to the admin.

    A real bolox to make, but a beaut in action...

    Watch her sail ...


    la la la ..

    Bed, now


Advertisement