0

I am trying to execute a shell command via:

<php echo shell_execute("tac /home/kusmuk/access-logs/kusmuk.org"); ?>

But it does not give any output. What could be the reason?

Although it does not work, the following lines work as expected:

<php echo shell_execute("ls -al triogrup.com"); ?>
//outputs: -rw-r----- 2 root kusmuk 28640 Aug 19 17:44 kusmuk.org

<php echo shell_execute("pwd"); ?>
//outputs: /home/kusmuk/public_html

2 Answers 2

2

Greg's tip is good. You'll probably end up with some kind of permissions problem.

However, I would say it's a good idea to avoid launching system calls from PHP if possible. The debugging can be a pain and if you're passing parameters it is very easy to make security holes. Native PHP code is much easier to handle.

‘tac’ is simple enough that you should be able to do it fine from within PHP. For example a trival version that spits out the whole file in one go:

$log= file_get_contents('/home/kusmuk/access-logs/kusmuk.org');
echo implode("\n", array_reverse(explode("\n", $log)));
Sign up to request clarification or add additional context in comments.

Comments

2

Try this:

echo shell_exec("tac /home/kusmuk/access-logs/kusmuk.org 2>&1");

It will redirect stderr to stdout so hopefully you should see why it's not working

1 Comment

It may be something simple like 'tac' not being in the PATH.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.