Jump to content

[SOLVED] shell_exec() problems


akkad

Recommended Posts

Hi,

my probelm is that i have full access to the shell of the server (fedora 3.1) but running this code in a php file on xampp server that i have on the same server , i am not getting the output even when i am trying to pipe the output to an html file .

<code>

 

shell_exec("cat `find ./logs -name access.log*` | grep akadi_icho | ./calamaris/calamaris -a -P 60 -T 0 -r 400 -d 500 -u -O -F html>akadi_icho.html");

 

</code>

but when i am running this code on the shell directly :

<code>

cat `find ./logs -name access.log*` | grep akadi_icho| ./calamaris/calamaris -a -P 60 -T 0 -r 400 -d 500 -u -O -F html>akadi_icho.html

</code>

it is working perfectly.

so i have tried to run the code in parts :

<code>

shell_exec("cat `find ./logs -name access.log*` | grep akadi_icho");

</code>

this part is working, but when i am running the whole part i am not getting any output.

 

so plz can u help me to figure out the problem.

 

Link to comment
https://forums.phpfreaks.com/topic/62631-solved-shell_exec-problems/
Share on other sites

Hi again , i appreciate ur help, i have used system() function in two ways:

$last_line = system( shell_exec('cat `find ./logs -name access.log*`|grep $userid |./calamaris/calamaris -a -P 60 -T 0 -r 400 -d 500 -u -O -F html'), $retval);
echo $retval;

the output was:

Warning: system() [function.system]: Cannot execute a blank command in /opt/lampp/htdocs/xampp/thesis/traffic.php on line 28

where line 28 is the system command by it self.

 

the second way :

$last_line = system('cat `find ./logs -name access.log*`|grep $userid |./calamaris/calamaris -a -P 60 -T 0 -r 400 -d 500 -u -O -F html', $retval);
echo $retval;

 

the output was :

126

 

related to the combining STDERR with STDOUT i dont know the right syntax if u can give me an example that i can figure out how to use it

 

i have used system() function in two ways:

 

The first is incorrect, the second is correct.

 

Since you're using single quotes $userid will not be interpolated. If double quotes don't fix the problem, try running pwd to make sure you're in the right directory.

 

related to the combining STDERR with STDOUT i dont know the right syntax if u can give me an example that i can figure out how to use it

 

<pre>
<?php
### This won't show you anything because it only returns STDOUT.
echo shell_exec('notacmd');

echo '<hr>';

### This will show the error because it returns STDOUT and STDERR.
echo shell_exec('notacmd 2>&1');
?>
</pre>

finally i could find the solution which is : in php code i couldn't run a perl script without calling the perl or bash to run it , so i have done that in the following way:

<code>

echo shell_exec("cat /opt/lampp/htdocs/xampp/thesis/logs/access.log.* | grep $userid | /usr/bin/perl  ./calamaris/calamaris -a -P 60 -T 0 -r 400 -d 500 -u -O -F html");

</code>

thanx buddy

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.