How can I run shell script in php program?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tim

    How can I run shell script in php program?

    I have tried to write a php program to execute the shell script,but
    dont know why it is not successful lei?
    file: test.php
    <?
    system("/home/www/htdocs/ok");
    ?>

    file: ok (permission 755)
    #!/bin/bash
    echo abc >> abc.txt

    Why it is not successful lei(still cant see any file named as abc.txt
    after run test.php)? I have tried other commands like shell_exec(),
    also not work.
  • CountScubula

    #2
    Re: How can I run shell script in php program?

    the directory you are in needs to allow the user apache or nobody (depends
    on your setup) to allow the creation of files.

    Simpler to do this
    create a dir within the dir you are in, call it _write or some thing to that
    effect.

    from the command line
    mkdir _write
    chmod 777 _write

    then adust you script as so.

    file: ok (permission 755)
    ----------------------------------
    #!/bin/bash
    echo abc >> ./_write/abc.txt

    this way any script can create a file in the _write dir.

    *or* you have to create the file abc.txt with nothing in it and make it
    writable


    --
    Mike Bradley
    http://www.gzentools.com -- free online php tools
    "Tim" <tim_li1008@sin aman.com> wrote in message
    news:e5ae706f.0 403112314.15c60 135@posting.goo gle.com...[color=blue]
    > I have tried to write a php program to execute the shell script,but
    > dont know why it is not successful lei?
    > file: test.php
    > <?
    > system("/home/www/htdocs/ok");
    > ?>
    >
    > file: ok (permission 755)
    > #!/bin/bash
    > echo abc >> abc.txt
    >
    > Why it is not successful lei(still cant see any file named as abc.txt
    > after run test.php)? I have tried other commands like shell_exec(),
    > also not work.[/color]


    Comment

    • root-boy

      #3
      Re: How can I run shell script in php program?

      tim_li1008@sina man.com (Tim) wrote in
      news:e5ae706f.0 403112314.15c60 135@posting.goo gle.com:
      [color=blue]
      > Why it is not successful lei(still cant see any file named as abc.txt
      > after run test.php)? I have tried other commands like shell_exec(),
      > also not work.
      >[/color]

      Try:

      `/home/www/htdocs/ok`;

      Note the '`' symbol, it's the one to the left, from your 1-key, above the
      TAB.

      Comment

      Working...