Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2003
    Location
    California
    Posts
    178

    Execute a linux shell cmd via PHP

    Hello,

    I need to learn the command to execute a linux shell command through PHP. The script will be owned by the same user that will also be running the PHP file. It will however be in a different directory. Can anyone give me a code or something on how to do this? Thanks a lot!
    Beep...

  2. #2
    Join Date
    Dec 2003
    Location
    ./Southest Missouri
    Posts
    601
    As long as PHP Safe Mode isn't enabled, you should be able to execute the script in a number of ways. You could use backticks, or you could use the shell_exec(), exec(), system(), or passthru() functions.

    If you'd like examples, there are more than plenty right here:

    http://us3.php.net/manual/en/function.shell-exec.php

  3. #3
    Join Date
    Aug 2003
    Location
    California
    Posts
    178
    Hey,

    Ya I used the shell_exec script but it won't let me execute a script to stop a game server. I am trying to execute a script that has inside of it: "killall -9 screen"

    This script works fine in ssh but when I run it through php for some reason it won't work... The server process I am trying to kill is owned by the user who is executing the script also. Yet I can execute other scripts that just echo stuff. Do you have any ideas?
    Beep...

  4. #4
    Join Date
    Jan 2005
    Location
    Leeds, England
    Posts
    183
    i had a PHP and python script set that did a start/stop for gameserver

    pythons runnign as a service on the linux server php sending commands

    worked really well... ill try and dig it out for you.

  5. #5
    Join Date
    Aug 2003
    Location
    California
    Posts
    178
    Thanks .
    Beep...

  6. #6
    Join Date
    Aug 2003
    Location
    California
    Posts
    178
    Hey. I think I found what the problem might be with executing this script. The server script that starts the game server will execute because I put in a couple cmds
    echo Starting
    echo Done
    And those output but the cmd in between it is
    screen ./hlds_run .......
    Does not run. I believe it may be the fact that I need to be connected to a terminal. Since when I tried to run the cmd to via the screen of the server it gave me this error:
    Must be connected to a terminal.

    How would I connect to a terminal?
    Thanks!
    Beep...

Posting Permissions

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