FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » php exec http url
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
php exec http url [message #185182] Thu, 06 March 2014 20:42 Go to next message
bishop2001 is currently offline  bishop2001
Messages: 1
Registered: March 2014
Karma: 0
Junior Member
Greetings,
I am trying to execute a shell script which is residing on a webserver on a remote machine with no luck. I have tried the following. It looks like it runs but I never see the output from the script on machine2. Any suggestions. Thanks,

from machine 1:
echo exec('http://machine2/script.sh);

and

from machine1:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://machine2/script.sh");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
?>
Re: php exec http url [message #185183 is a reply to message #185182] Thu, 06 March 2014 21:04 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 3/6/2014 3:42 PM, bishop2001 wrote:
> Greetings,
> I am trying to execute a shell script which is residing on a webserver on a remote machine with no luck. I have tried the following. It looks like it runs but I never see the output from the script on machine2. Any suggestions. Thanks,
>
> from machine 1:
> echo exec('http://machine2/script.sh);
>
> and
>
> from machine1:
> <?php
> $ch = curl_init();
> curl_setopt($ch, CURLOPT_URL, "http://machine2/script.sh");
> curl_setopt($ch, CURLOPT_HEADER, 0);
> curl_exec($ch);
> curl_close($ch);
> ?>
>

What is the result of your curl_exec()? How do you know the shell
script is working? What happens when you try to execute the shell
script from a browser?


--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
Re: php exec http url [message #185188 is a reply to message #185182] Fri, 07 March 2014 14:09 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
bishop2001 wrote:
^^^^^^^^^^
Please fix.

> I am trying to execute a shell script which is residing on a webserver on
> a remote machine with no luck. I have tried the following. It looks like
> it runs but I never see the output from the script on machine2. Any
> suggestions. Thanks,
>
> from machine 1:
> echo exec('http://machine2/script.sh);

exec() executes commands in the shell running on the local machine (where
PHP is running), assuming it is allowed (for security reasons, it usually is
not). http://machine2/script.sh is not a command in any known shell
script language.

> and
>
> from machine1:
> <?php
> $ch = curl_init();
> curl_setopt($ch, CURLOPT_URL, "http://machine2/script.sh");
> curl_setopt($ch, CURLOPT_HEADER, 0);
> curl_exec($ch);
> curl_close($ch);
> ?>

Even if a Web server would serve that resource, it would not execute it by
default, IOW by default you would receive only the source code of the shell
script, not its output.


PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
Re: php exec http url [message #185189 is a reply to message #185188] Fri, 07 March 2014 14:55 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
On 07/03/14 14:09, Thomas 'PointedEars' Lahn wrote:
> bishop2001 wrote:
> ^^^^^^^^^^
> Please fix.
>
>> I am trying to execute a shell script which is residing on a webserver on
>> a remote machine with no luck. I have tried the following. It looks like
>> it runs but I never see the output from the script on machine2. Any
>> suggestions. Thanks,
>>
>> from machine 1:
>> echo exec('http://machine2/script.sh);
>
> exec() executes commands in the shell running on the local machine (where
> PHP is running), assuming it is allowed (for security reasons, it usually is
> not). http://machine2/script.sh is not a command in any known shell
> script language.
>
>> and
>>
>> from machine1:
>> <?php
>> $ch = curl_init();
>> curl_setopt($ch, CURLOPT_URL, "http://machine2/script.sh");
>> curl_setopt($ch, CURLOPT_HEADER, 0);
>> curl_exec($ch);
>> curl_close($ch);
>> ?>
>
> Even if a Web server would serve that resource, it would not execute it by
> default, IOW by default you would receive only the source code of the shell
> script, not its output.
>
>
> PointedEars
>

The way to do this is to set php up on the remote server to have a web
page run that script.

e.g. on the machine2 that runs a script have a php file that does this

echo (exec('script.sh'));

and then on machine1 simply use curl to point not at the script, but at
the URL of the php file that actually runs that script.





--
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to
lead are elected by the least capable of producing, and where the
members of society least likely to sustain themselves or succeed, are
rewarded with goods and services paid for by the confiscated wealth of a
diminishing number of producers.
Re: php exec http url [message #185190 is a reply to message #185189] Fri, 07 March 2014 15:36 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
The Natural Philosopher wrote:
^^^^^^^^^^^^^^^^^^^^^^^
Please fix.

> On 07/03/14 14:09, Thomas 'PointedEars' Lahn wrote:
>> bishop2001 wrote:
>>> from machine1:
>>> <?php
>>> $ch = curl_init();
>>> curl_setopt($ch, CURLOPT_URL, "http://machine2/script.sh");
>>> curl_setopt($ch, CURLOPT_HEADER, 0);
>>> curl_exec($ch);
>>> curl_close($ch);
>>> ?>
>>
>> Even if a Web server would serve that resource, it would not execute it
>> by default, IOW by default you would receive only the source code of the
>> shell script, not its output.
>
> The way to do this is to set php up on the remote server to have a web
> page run that script.
>
> e.g. on the machine2 that runs a script have a php file that does this
>
> echo (exec('script.sh'));
>
> and then on machine1 simply use curl to point not at the script, but at
> the URL of the php file that actually runs that script.

That is not the only way.

Your From header field still violates RFC 5536, and several other
conventions and rules.

Learn to quote.


PointedEars
--
When all you know is jQuery, every problem looks $(olvable).
Re: php exec http url [message #185192 is a reply to message #185182] Fri, 07 March 2014 18:12 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Thu, 06 Mar 2014 12:42:52 -0800, bishop2001 wrote:

> Greetings,
> I am trying to execute a shell script which is residing on a webserver
> on a remote machine with no luck. I have tried the following. It looks
> like it runs but I never see the output from the script on machine2. Any
> suggestions. Thanks,

Firstly, you say "It looks like it runs"

What evidence do you have for this?

> from machine 1:
> echo exec('http://machine2/script.sh);

What entries appear in the webserver logs on the server after attempting
this? You probably want to check any log file in the apache logs dir that
has it's timestamp modified when you try and access the script.

> from machine1:
> <?php $ch = curl_init();
> curl_setopt($ch, CURLOPT_URL, "http://machine2/script.sh");
> curl_setopt($ch, CURLOPT_HEADER, 0);
> curl_exec($ch);
> curl_close($ch);
> ?>

What entries appear in the webserver logs on the server after attempting
this?

Are you sure that the webserver is configured to run .sh files as shell
scripts and pipe the output of the script back to the http session?

Are you sure that the script is executable by the webserver process?
Execute permissions for relevant users / groups / world?

--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
Re: php exec http url [message #185193 is a reply to message #185190] Fri, 07 March 2014 20:33 Go to previous message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
On 07/03/14 15:36, Thomas 'PointedEars' Lahn wrote:
> The Natural Philosopher wrote:
> ^^^^^^^^^^^^^^^^^^^^^^^
> Please fix.
>
>> On 07/03/14 14:09, Thomas 'PointedEars' Lahn wrote:
>>> bishop2001 wrote:
>>>> from machine1:
>>>> <?php
>>>> $ch = curl_init();
>>>> curl_setopt($ch, CURLOPT_URL, "http://machine2/script.sh");
>>>> curl_setopt($ch, CURLOPT_HEADER, 0);
>>>> curl_exec($ch);
>>>> curl_close($ch);
>>>> ?>
>>>
>>> Even if a Web server would serve that resource, it would not execute it
>>> by default, IOW by default you would receive only the source code of the
>>> shell script, not its output.
>>
>> The way to do this is to set php up on the remote server to have a web
>> page run that script.
>>
>> e.g. on the machine2 that runs a script have a php file that does this
>>
>> echo (exec('script.sh'));
>>
>> and then on machine1 simply use curl to point not at the script, but at
>> the URL of the php file that actually runs that script.
>
> That is not the only way.
>
> Your From header field still violates RFC 5536, and several other
> conventions and rules.
>
> Learn to quote.
>
>
> PointedEars
>

Fuck off noddy

--
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to
lead are elected by the least capable of producing, and where the
members of society least likely to sustain themselves or succeed, are
rewarded with goods and services paid for by the confiscated wealth of a
diminishing number of producers.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Experienced Web designer required
Next Topic: When a random file is not found then what?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 21 17:58:55 GMT 2024

Total time taken to generate the page: 0.02416 seconds