Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #5530 > unrolled thread
| Started by | 7segment <7segment@nowhere.com> |
|---|---|
| First post | 2012-04-15 11:37 -0500 |
| Last post | 2012-04-16 14:43 +0200 |
| Articles | 16 — 6 participants |
Back to article view | Back to comp.lang.php
problems with exec() 7segment <7segment@nowhere.com> - 2012-04-15 11:37 -0500
Re: problems with exec() 7segment <7segment@nowhere.com> - 2012-04-15 11:47 -0500
Re: problems with exec() Jerry Stuckle <jstucklex@attglobal.net> - 2012-04-15 13:34 -0400
Re: problems with exec() "J.O. Aho" <user@example.net> - 2012-04-15 19:43 +0200
Re: problems with exec() "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-04-16 00:16 +0200
Re: problems with exec() "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-04-16 00:22 +0200
Re: problems with exec() "J.O. Aho" <user@example.net> - 2012-04-16 07:17 +0200
Re: problems with exec() Une Bévue <unbewusstsein@fai.invalid> - 2012-04-16 10:07 +0200
Re: problems with exec() "J.O. Aho" <user@example.net> - 2012-04-16 19:29 +0200
Re: problems with exec() Une Bévue <unbewusstsein@fai.invalid> - 2012-04-18 15:44 +0200
Re: problems with exec() "J.O. Aho" <user@example.net> - 2012-04-18 18:02 +0200
Re: problems with exec() Une Bévue <unbewusstsein@fai.invalid> - 2012-04-18 19:43 +0200
Re: problems with exec() "J.O. Aho" <user@example.net> - 2012-04-18 20:37 +0200
Re: problems with exec() Une Bévue <unbewusstsein@fai.invalid> - 2012-04-18 23:31 +0200
Re: problems with exec() Kim André Akerø <kimandre@nospambetadome.com> - 2012-04-16 13:27 +0200
Re: problems with exec() "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-04-16 14:43 +0200
| From | 7segment <7segment@nowhere.com> |
|---|---|
| Date | 2012-04-15 11:37 -0500 |
| Subject | problems with exec() |
| Message-ID | <9-SdnWmoCP7eZBfSnZ2dnUVZ7q6dnZ2d@giganews.com> |
Hi.
I have an interesting problem and I cannot figure out what the problem
might be.
This does not produce any output:
$response = exec('ifconfig');
echo $response[0];
Although when I try other commands, I get a response on the screen. So I
don't get what's so special about ifconfig.
Could anyone help please?
7segment
[toc] | [next] | [standalone]
| From | 7segment <7segment@nowhere.com> |
|---|---|
| Date | 2012-04-15 11:47 -0500 |
| Message-ID | <9-SdnWioCP4HZhfSnZ2dnUVZ7q6dnZ2d@giganews.com> |
| In reply to | #5530 |
Sorry this was the code I wanted to cite:
$response = exec('ifconfig');
echo $response;
On Sun, 15 Apr 2012 11:37:23 -0500, 7segment wrote:
> Hi.
>
> I have an interesting problem and I cannot figure out what the problem
> might be.
>
> This does not produce any output:
>
> $response = exec('ifconfig');
> echo $response[0];
>
> Although when I try other commands, I get a response on the screen. So I
> don't get what's so special about ifconfig.
>
> Could anyone help please?
>
> 7segment
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2012-04-15 13:34 -0400 |
| Message-ID | <jmf0r2$6kf$1@dont-email.me> |
| In reply to | #5531 |
On 4/15/2012 12:47 PM, 7segment wrote:
> Sorry this was the code I wanted to cite:
>
> $response = exec('ifconfig');
> echo $response;
>
> On Sun, 15 Apr 2012 11:37:23 -0500, 7segment wrote:
>
>> Hi.
>>
>> I have an interesting problem and I cannot figure out what the problem
>> might be.
>>
>> This does not produce any output:
>>
>> $response = exec('ifconfig');
>> echo $response[0];
>>
>> Although when I try other commands, I get a response on the screen. So I
>> don't get what's so special about ifconfig.
>>
>> Could anyone help please?
>>
>> 7segment
>
Do you have permission to run ifconfig? Normally the web server does
not have nearly enough permissions to reconfigure the network adapters
(which is as it should be).
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[toc] | [prev] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2012-04-15 19:43 +0200 |
| Message-ID | <9v0fldFforU1@mid.individual.net> |
| In reply to | #5530 |
7segment wrote:
> Hi.
>
> I have an interesting problem and I cannot figure out what the problem
> might be.
>
> This does not produce any output:
>
> $response = exec('ifconfig');
> echo $response;
>
> Although when I try other commands, I get a response on the screen. So I
> don't get what's so special about ifconfig.
>
> Could anyone help please?
ifconfig usually residence in /sbin (some GNU/Linux distribution are in the
migration path of moving it to /usr/sbin), this directory is never in a
normal users or a daemon users $PATH, so you need to give the whole path to
this binary to be able to run it.
By default the file is executional by all users, but someone may have changed
permissions or setup ACL rules with for example SELinux.
--
//Aho
[toc] | [prev] | [next] | [standalone]
| From | "M. Strobel" <sorry_no_mail_here@nowhere.dee> |
|---|---|
| Date | 2012-04-16 00:16 +0200 |
| Message-ID | <9v0vlnF4m6U2@mid.uni-berlin.de> |
| In reply to | #5533 |
Am 15.04.2012 19:43, schrieb J.O. Aho:
> 7segment wrote:
>> Hi.
>>
>> I have an interesting problem and I cannot figure out what the problem
>> might be.
>>
>> This does not produce any output:
>>
>> $response = exec('ifconfig');
>> echo $response;
>>
>> Although when I try other commands, I get a response on the screen. So I
>> don't get what's so special about ifconfig.
>>
>> Could anyone help please?
>
> ifconfig usually residence in /sbin (some GNU/Linux distribution are in the migration
> path of moving it to /usr/sbin), this directory is never in a normal users or a
> daemon users $PATH, so you need to give the whole path to this binary to be able to
> run it.
>
> By default the file is executional by all users, but someone may have changed
> permissions or setup ACL rules with for example SELinux.
>
I can tell that on opensuse it it not executable by normal users.
/Str.
[toc] | [prev] | [next] | [standalone]
| From | "M. Strobel" <sorry_no_mail_here@nowhere.dee> |
|---|---|
| Date | 2012-04-16 00:22 +0200 |
| Message-ID | <9v100mF8g6U1@mid.uni-berlin.de> |
| In reply to | #5535 |
Am 16.04.2012 00:16, schrieb M. Strobel:
> Am 15.04.2012 19:43, schrieb J.O. Aho:
>> 7segment wrote:
>>> Hi.
>>>
>>> I have an interesting problem and I cannot figure out what the problem
>>> might be.
>>>
>>> This does not produce any output:
>>>
>>> $response = exec('ifconfig');
>>> echo $response;
>>>
>>> Although when I try other commands, I get a response on the screen. So I
>>> don't get what's so special about ifconfig.
>>>
>>> Could anyone help please?
>>
>> ifconfig usually residence in /sbin (some GNU/Linux distribution are in the migration
>> path of moving it to /usr/sbin), this directory is never in a normal users or a
>> daemon users $PATH, so you need to give the whole path to this binary to be able to
>> run it.
>>
>> By default the file is executional by all users, but someone may have changed
>> permissions or setup ACL rules with for example SELinux.
>>
>
> I can tell that on opensuse it it not executable by normal users.
>
Correct is: on suse it is not found on the path. When called with path /sbin/ifconfig
in a shell it outputs the NIC configuration. When called like that it outputs nothing:
php > $a = exec('/sbin/ifconfig');
php > echo $a;
php > var_dump($a);
string(0) ""
/Str.
[toc] | [prev] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2012-04-16 07:17 +0200 |
| Message-ID | <9v1oc1FvdvU1@mid.individual.net> |
| In reply to | #5536 |
M. Strobel wrote:
> Am 16.04.2012 00:16, schrieb M. Strobel:
>> Am 15.04.2012 19:43, schrieb J.O. Aho:
>>> 7segment wrote:
>>>> Hi.
>>>>
>>>> I have an interesting problem and I cannot figure out what the problem
>>>> might be.
>>>>
>>>> This does not produce any output:
>>>>
>>>> $response = exec('ifconfig');
>>>> echo $response;
>>>>
>>>> Although when I try other commands, I get a response on the screen. So I
>>>> don't get what's so special about ifconfig.
>>>>
>>>> Could anyone help please?
>>>
>>> ifconfig usually residence in /sbin (some GNU/Linux distribution are in the migration
>>> path of moving it to /usr/sbin), this directory is never in a normal users or a
>>> daemon users $PATH, so you need to give the whole path to this binary to be able to
>>> run it.
>>>
>>> By default the file is executional by all users, but someone may have changed
>>> permissions or setup ACL rules with for example SELinux.
>>>
>>
>> I can tell that on opensuse it it not executable by normal users.
>>
>
> Correct is: on suse it is not found on the path. When called with path /sbin/ifconfig
> in a shell it outputs the NIC configuration. When called like that it outputs nothing:
>
> php> $a = exec('/sbin/ifconfig');
> php> echo $a;
> php> var_dump($a);
> string(0) ""
Think the ifconfig makes a bit environment check and wants a shell, use
shell_exec instead and you will see the output.
--
//Aho
[toc] | [prev] | [next] | [standalone]
| From | Une Bévue <unbewusstsein@fai.invalid> |
|---|---|
| Date | 2012-04-16 10:07 +0200 |
| Message-ID | <4f8bd352$0$21937$426a34cc@news.free.fr> |
| In reply to | #5537 |
Le 16/04/2012 07:17, J.O. Aho a écrit :
>>
>> php> $a = exec('/sbin/ifconfig');
>> php> echo $a;
>> php> var_dump($a);
>> string(0) ""
>
> Think the ifconfig makes a bit environment check and wants a shell, use
> shell_exec instead and you will see the output.
>
On Ubuntu 11.10, this works very well :
$lines=explode("\n", shell_exec('/sbin/ifconfig'));
foreach ($lines as $line) {
echo "$line<br />";
}
may be the prob i had creating an ssh tunnel comes also from the
difference between "exec" and "shell_exec" ?
[toc] | [prev] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2012-04-16 19:29 +0200 |
| Message-ID | <9v338gFtdpU1@mid.individual.net> |
| In reply to | #5539 |
Une Bévue wrote:
> Le 16/04/2012 07:17, J.O. Aho a écrit :
>>>
>>> php> $a = exec('/sbin/ifconfig');
>>> php> echo $a;
>>> php> var_dump($a);
>>> string(0) ""
>>
>> Think the ifconfig makes a bit environment check and wants a shell, use
>> shell_exec instead and you will see the output.
>>
>
> On Ubuntu 11.10, this works very well :
> $lines=explode("\n", shell_exec('/sbin/ifconfig'));
> foreach ($lines as $line) {
> echo "$line<br />";
> }
>
> may be the prob i had creating an ssh tunnel comes also from the difference
> between "exec" and "shell_exec" ?
I suspect it could have the same issue, try to use shell_exec and let us know
if it works.
--
//Aho
[toc] | [prev] | [next] | [standalone]
| From | Une Bévue <unbewusstsein@fai.invalid> |
|---|---|
| Date | 2012-04-18 15:44 +0200 |
| Message-ID | <4f8ec54d$0$16482$426a74cc@news.free.fr> |
| In reply to | #5546 |
Le 16/04/2012 19:29, J.O. Aho a écrit : > I suspect it could have the same issue, try to use shell_exec and let us > know if it works. Unfortunately, not. i suspect because the line : $cmd = ssh -L 63333:localhost:5432 -f yt@iMac -N is without password for the user 'yt' not for php being of user 'www_data' on Ubuntu. Nevertheless i got that pgsql db working remotly after editing pg_hba.conf.
[toc] | [prev] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2012-04-18 18:02 +0200 |
| Message-ID | <9v86s3FrkcU1@mid.individual.net> |
| In reply to | #5560 |
Une Bévue wrote: > Le 16/04/2012 19:29, J.O. Aho a écrit : >> I suspect it could have the same issue, try to use shell_exec and let us >> know if it works. > > Unfortunately, not. > i suspect because the line : > > $cmd = ssh -L 63333:localhost:5432 -f yt@iMac -N > > is without password for the user 'yt' not for php being of user 'www_data' on > Ubuntu. > > Nevertheless i got that pgsql db working remotly after editing pg_hba.conf. Otherwise, you can copy the public key to the www-data users ~/.ssh and the ssh would have worked. Of course you could have setup a cron job instead which would recreated the tunnel each time it went down. Of course those two solutions aren't as good as using the proper method. -- //Aho
[toc] | [prev] | [next] | [standalone]
| From | Une Bévue <unbewusstsein@fai.invalid> |
|---|---|
| Date | 2012-04-18 19:43 +0200 |
| Message-ID | <4f8efd29$0$21917$426a74cc@news.free.fr> |
| In reply to | #5561 |
Le 18/04/2012 18:02, J.O. Aho a écrit : > > Otherwise, you can copy the public key to the www-data users ~/.ssh and > the ssh would have worked. Of course you could have setup a cron job > instead which would recreated the tunnel each time it went down. > Of course those two solutions aren't as good as using the proper method. ok, thanks. In fact i've used the ssh tunnel because it was the simplest : create the tunnel and use the psql server as if it is local.
[toc] | [prev] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2012-04-18 20:37 +0200 |
| Message-ID | <9v8g01F2rjU1@mid.individual.net> |
| In reply to | #5562 |
Une Bévue wrote: > Le 18/04/2012 18:02, J.O. Aho a écrit : >> >> Otherwise, you can copy the public key to the www-data users ~/.ssh and >> the ssh would have worked. Of course you could have setup a cron job >> instead which would recreated the tunnel each time it went down. >> Of course those two solutions aren't as good as using the proper method. > > ok, thanks. > In fact i've used the ssh tunnel because it was the simplest : > create the tunnel and use the psql server as if it is local. *nods* In a way it's easy, but at the same time you get something more that can fail and it can be looking strange in the error messages when the ssh tunnel is still there while the other end of the tunnel don't work, seen issues with that at a company I used to work for. I haven't followed your thread, but you know that user A can setup the tunnel and user B can use it. -- //Aho
[toc] | [prev] | [next] | [standalone]
| From | Une Bévue <unbewusstsein@fai.invalid> |
|---|---|
| Date | 2012-04-18 23:31 +0200 |
| Message-ID | <4f8f32a7$0$13209$426a34cc@news.free.fr> |
| In reply to | #5563 |
On 18/04/12 20:37, J.O. Aho wrote: > I haven't followed your thread, but you know that user A can setup the > tunnel and user B can use it. Yes, thanks, in fact i used the tunnel only to start with by the time i setup pg_hba.conf.
[toc] | [prev] | [next] | [standalone]
| From | Kim André Akerø <kimandre@nospambetadome.com> |
|---|---|
| Date | 2012-04-16 13:27 +0200 |
| Message-ID | <op.wcuvfemmptrp3x@neonk2.intrahouse.local> |
| In reply to | #5530 |
På Sun, 15 Apr 2012 18:37:23 +0200, skrev 7segment <7segment@nowhere.com>:
> Hi.
>
> I have an interesting problem and I cannot figure out what the problem
> might be.
>
> This does not produce any output:
>
> $response = exec('ifconfig');
> echo $response[0];
>
> Although when I try other commands, I get a response on the screen. So I
> don't get what's so special about ifconfig.
>
> Could anyone help please?
Based on your corrected code in your own reply, which lists the second
line as "echo $response;", I can see what you problem would be.
Even if you're allowed to run this particular command from your PHP
script, the return value of exec() is always the LAST line of the command
output. On my system, the last line of the "ifconfig" command is always
blank, which is what $response in your code example would contain. Try
instead to do it like this (and, preferrably, include the full path of
ifconfig):
exec('/sbin/ifconfig', $response); // $response is an array
echo implode('\n', $response);
--
Kim André Akerø
- kimandre@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
[toc] | [prev] | [next] | [standalone]
| From | "M. Strobel" <sorry_no_mail_here@nowhere.dee> |
|---|---|
| Date | 2012-04-16 14:43 +0200 |
| Message-ID | <9v2if4Fu3uU1@mid.uni-berlin.de> |
| In reply to | #5541 |
Am 16.04.2012 13:27, schrieb Kim André Akerø:
> På Sun, 15 Apr 2012 18:37:23 +0200, skrev 7segment <7segment@nowhere.com>:
>
>> Hi.
>>
>> I have an interesting problem and I cannot figure out what the problem
>> might be.
>>
>> This does not produce any output:
>>
>> $response = exec('ifconfig');
>> echo $response[0];
>>
>> Although when I try other commands, I get a response on the screen. So I
>> don't get what's so special about ifconfig.
>>
>> Could anyone help please?
>
> Based on your corrected code in your own reply, which lists the second line as "echo
> $response;", I can see what you problem would be.
>
> Even if you're allowed to run this particular command from your PHP script, the
> return value of exec() is always the LAST line of the command output. On my system,
> the last line of the "ifconfig" command is always blank, which is what $response in
> your code example would contain. Try instead to do it like this (and, preferrably,
> include the full path of ifconfig):
Very convincing, thank you. I was about to test why ifconfig would need the shell
environment...
/Str.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web