Re: php exec http url [message #185189 is a reply to message #185188] |
Fri, 07 March 2014 14:55 |
The Natural Philosoph
Messages: 993 Registered: September 2010
Karma:
|
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.
|
|
|