Results 1 to 6 of 6

Thread: Run a linux script from a PHP file!

  1. #1

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Run a linux script from a PHP file!

    I know this should frikkin work but it's been pissing me off all night and I can't figure it out. I'm using shell_exec('/media/<....>/mine/script.sh'); and IT WILL NOT RUN RIGHT!!!

    If I echo that command and put a return in the script, it outputs that return line. There seems to be NO errors running anything. WFT is the problem?? I've chmod'd 777 to the file, tried changing the file owner to root and nobody and NOTHING WORKS!!!! Can anyone explain why?

    Latest Apache/PHP5, Ubuntu Linux


    BTW the script is 3 lines really and it runs fine in a terminal on the server.

    import -window root /media/disk/apache2dir/mine/screenshot.png
    echo This should have ****ing worked!!
    exit
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Run a linux script from a PHP file!

    I'm sorry but your question confuses me.

    What do you expect to happen?

  3. #3

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Re: Run a linux script from a PHP file!

    It should run a script (screenshot.sh) and that script will take a screenshot and save it to /media/disk/apache2dir/mine/screenshot.png, then my script will redirect to that screenshot png. The idea of the whole thing is to be able to see a screenshot on my server from anywhere I want.

    EDIT

    OK, I've also determined that changing the owner does nothing. Also, CRON cannot run the job either. It seems ONLY to run when used at the command line. Any ideas anyone?
    Last edited by ididntdoit; May 21st, 2009 at 04:02 PM.
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

  4. #4
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: Run a linux script from a PHP file!

    When you run it from command prompt, are you using sudo, or the command prompt is root's?

    I only know a little about Linux, but it's the only thing I can think of.

  5. #5

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Re: Run a linux script from a PHP file!

    no sudo. But it does work with sudo.
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

  6. #6

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Re: Run a linux script from a PHP file!

    OK FYI it turns out that Cron and PHP do not by default have access to the X server in linux. To make my script (below) work with Cron, you must include a path to the DISPLAY environment variable. I think the reason that doesn't solve the PHP problem is that PHP has some issues with security when it comes to linux. I'm not quite sure how to address them.

    Does anyone know?


    Code:
    #!/bin/bash
    SHELL=/bin/sh
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    DISPLAY=:0
    export DISPLAY;
    HOME=/home/browner87
    export HOME;
    /usr/bin/import -display :0.0 -window root -silent /media/disk/thepath/screenshot.png
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

Posting Permissions

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



Click Here to Expand Forum to Full Width