Jump to content


Photo

Exec() nohup command


  • Please log in to reply
4 replies to this topic

#1 pmzq

pmzq
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 18 July 2006 - 09:13 PM

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,

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 19 July 2006 - 06:36 AM

Have you tried adding the output parameter to the exec() function to see if it is spitting out any error messages?

#3 pmzq

pmzq
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 19 July 2006 - 12:43 PM

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,

#4 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 19 July 2006 - 03:35 PM

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


Check out the manual page for exec() for any further details regarding the workings of the function.

#5 pmzq

pmzq
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 19 July 2006 - 08:30 PM

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,




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users