Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

php exec http url

802 views
Skip to first unread message

bishop2001

unread,
Mar 6, 2014, 3:42:52 PM3/6/14
to
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);
?>

Jerry Stuckle

unread,
Mar 6, 2014, 4:04:53 PM3/6/14
to
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
jstu...@attglobal.net
==================

Thomas 'PointedEars' Lahn

unread,
Mar 7, 2014, 9:09:24 AM3/7/14
to
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.)

The Natural Philosopher

unread,
Mar 7, 2014, 9:55:02 AM3/7/14
to
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.

Thomas 'PointedEars' Lahn

unread,
Mar 7, 2014, 10:36:13 AM3/7/14
to
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).

Denis McMahon

unread,
Mar 7, 2014, 1:12:37 PM3/7/14
to
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, denismf...@gmail.com

The Natural Philosopher

unread,
Mar 7, 2014, 3:33:53 PM3/7/14
to
Fuck off noddy
0 new messages