Jump to content

Archived

This topic is now archived and is closed to further replies.

pmzq

Exec() nohup command

Recommended Posts

Ok people here we go:
I've been trying to  get a certain .php file to execute a .sh file on my server.
When I'm on the server in a shell and I axecute the following command:
nohup /wwwroot/htdocs/test/ticker/tick.sh
Then the tick.sh file is executed and is running in the background which is what I want.

Now my question is to run the same command, but I want to run it from a php file in on the server. Somewere in /wwwroot/htdocs/test

I thought It would be easy to just do the following:
exec("nohup /wwwroot/htdocs/test/ticker/tick_test.sh") ;

Well yes it did NOT  :o I've read lots of articles about this isue but can't seem to find a sollution.

Is there a problem with my server do I need to login on the server first with a PHP script in order to execute such a command ?

Hope to hear something soon

Greetzz pMzQ,

Share this post


Link to post
Share on other sites
Have you tried adding the output parameter to the exec() function to see if it is spitting out any error messages?

Share this post


Link to post
Share on other sites
If I knew how to add such a output to my command ? Can you give me an example ?

( yes I am a noob :D )

pMzQ,

Share this post


Link to post
Share on other sites
[code=php:0]exec("nohup /wwwroot/htdocs/test/ticker/tick_test.sh",$output);
echo "<pre>"; print_r($output); echo "</pre>";[/code]


Check out [url=http://www.php.net/exec]the manual page for exec()[/url] for any further details regarding the workings of the function.

Share this post


Link to post
Share on other sites
Ok I did the following:


exec("nohup /wwwroot/htdocs/test/ticker/tick_test.sh",$output);
echo "<pre>"; print_r($output); echo "</pre>";

I've putt this command in a php file and when I open the file it keeps on loading untill forever!

When I go into ssh with putty and I kill the tick_test.sh file by typing kill $pid number i received with pgrep tick_test.sh

then when I go to the page that exectuted the file it returns the following:



Array
(
    [0] => *** wo jul 19 22:13:29 CEST 2006 ***
    [1] => *sleeping
    [2] => *** wo jul 19 22:13:29 CEST 2006 ***
    [3] => *sleeping
    [4] => *** wo jul 19 22:13:29 CEST 2006 ***
    [5] => *sleeping
    [6] => *** wo jul 19 22:13:29 CEST 2006 ***
    [7] => *sleeping

etc etc etc..
until

[1166] => Quiting through clean_up
    [1167] => Quiting through clean_up

that's it ????

I set the permission for the ticker directory to 777 so don't think that has anything to do with it does it ?

Hoppe to hear from ya soon thnx!
pMzQ,

p.s. I tried also something else:

Here is the code of the tick_test.sh file:

trap clean_up EXIT SIGTERM SIGKILL SIGABRT

function clean_up() {

  echo "Quiting through clean_up"
  rm ./ticker.run
  rm ./ticker.run.timer
  rm ./ticker.end


  trap EXIT
  exit 0
}

if [ $# -eq 1 ]; then
  tick=$1
else
  tick=30
fi

if [ ! -f ticker.end ]; then
  touch ./ticker.end
fi
touch ./ticker.run.timer

while [ 1 ]; do
  echo "*** "`date`" ***"
  ./ticker mypa.cfg
  echo "*sleeping $sleep"
  ./tick_sleep $tick ./ticker.run.timer


I did the following

system("nohup /wwwroot/htdocs/test/ticker/tick.sh 2>&1 &",$output);
echo "<pre>"; print_r($output); echo "</pre>";

then the output tells me this:

touch: cannot touch `./ticker.end' access denied and also:

*sleeping /wwwroot/htdocs/test/ticker/tick.sh: line 50 unknown file or directory.

So aren't the privilidges ok ?

thnx
pMzQ,

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.