You need to watch your quotes and escaping. In PHP this is all one big double-quoted section, and any double quotes inside it must be escaped so they don't end early.
Generally in PHP you are better off with a simple shell_exec() command and then process the results in PHP.
For example, from the above code, you could do this:
<?php
$command = "tail -n 11 /var/log/_gateway-syslog.log");
$raw_output = shell_exec($command);
$output = process_output($raw_output):
echo "<pre>$output</pre>";
function process_output($text)
{
// do your text processing here instead of using a shell command pipeline in shell_exec()
return $processed_text;
}
PHP has rich tools for text processing including regular expressions.
I written these types of PHP files to display unix / linux system information countless times, and I always process the text in PHP without exception.
In general, I find it best to decouple the "shell exec" type of commands from PHP as much as possible for a number of reasons, including system security, integrity and long-term system maintenance.
For a real-world example on this web site, we use shell_exec() to begin processing all the man pages in our man page repository; but the shell_exec() only returns the raw output from the man command. Then the PHP script extensively processes the raw man page output, adding links, formatting, html entities, css information, etc. There is a significant amount of text processing done in PHP, but the PHP shell_exec() command to get the man page from the Linux filesystem and output for processing is very basic / simple.
Corona688, Thank you. That was the quick fix and it worked....
Neo,
Thank you, I like your idea and I have followed the logic in your suggestion. However I am lost when it gets to processed_output. everything I have tried gives me no output.
I even replaced the tail -n with just cat to make sure I would see something. under the function process_output I ran a simple test using a grep for 20.254 . I'm seeing nothing.