Results 1 to 7 of 7
  1. #1

    Question PHP calling shell script

    Hello

    I need to use PHP to pass parameter values
    to shell
    but I don't know how to do it!!

    pls help!

    thanks a lot

  2. #2
    Join Date
    Nov 2003
    Posts
    691
    Look at these functions
    http://php.net/exec
    http://php.net/system

  3. #3

    hm

    if you do a

    ./php testvar.php -f=plah -g=pleh ,xyz=fnuk

    to start your php from shell

    then try "testvar.php" with the following code

    #!/usr/bin/php
    <?
    var_dump($argv);
    ?>

    i guess its what youre looking for

  4. #4

    I try that

    Umm I try to make usershow.sh to recieve from viewuser.php
    in php file I can use exec() to run usershow.sh
    but I want to pass parameter such as $username
    to shell script but I don't know how to write shell to recieve and how php pass value to shell by use exec() or system()

    Thanks for every one

  5. #5
    Join Date
    May 2002
    Location
    Finland
    Posts
    11
    I hope this gives you an idea, if i understood you correctly try this:
    PHP part:

    <?php
    system('/path/to/test.sh variable1');
    ?>

    Shell (bash) part:

    #!/bin/bash
    echo $1


    Chmod the .sh with something like 755 and then run your php script

  6. #6

    hm

    if you want to pass params during the runtime, you need to use any stream for.

    i.e.

    you can read a textfile for new lines
    also you could stress mysql (selecting a table)
    or you implement a socketlistener (AF_UNIX) to your script

    else threre is no chance to passing vars during the scriptruntime. Not that i know.

  7. #7
    It still not work for use php to pass value to shell
    I'm ok to write shell to recieve parameter form console
    but pass with PHP is still not work
    example

    I write
    on PHP
    <?
    shell_exec(" ./mkdir.sh newdir ");
    ?>

    on shell
    #!/bin/bash
    mkdir $1

    and chmod 755 with shell
    I can run shell by command line ./mkdir.sh new_dir

    It's OK

    What should I do in this way or I have another problem with server sevice because my RH9 server is not compleately runing well

    Thanks a lot for every one

Posting Permissions

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