Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute command give top: failed tty get

Tags:

php

ssh

centos

I have a problem when executing this line shown below.

sudo /usr/bin/env TERM=xterm /usr/bin/php /home/folder/folder/script.php -b val -a 2018-07-01

It gives me a error top: failed tty get. When I try it with php -f it gives me another problem similar to php --help.

[0] => Array
        (
            [error] => 1
            [return] =>     top: failed tty get


        )

The result that I want is to execute command with success not error I execute this command with SSH in a PHP script.

like image 661
HamzaNig Avatar asked Jul 09 '18 15:07

HamzaNig


1 Answers

Really could do with a copy of your PHP script here (as requested in comments) to confirm, but based on what you've provided:

It appears what you are trying to do it run "top" in some configuration that requires terminal in a PHP script.

/home/folder/folder/script.php
<?php

exec('top -n 1 -b', $out, $error);

print_r($out);

called by

/usr/bin/php /home/folder/folder/script.php

There are two solutions:

1) Using the above parameters (-n 1 -b) runs in batch mode for one iteration - tested Centos7. This should not need terminal and adds the output to an array. This could be what you need. But if it still fails:

2) Otherwise, you can specify the TERM=xterm - it looks like this is what you've attempted to do, but you need to to it inside the exec, and not in the shell that calls the php script.

/home/folder/folder/script.php
<?php

exec('TERM=xterm top -n 1 -b', $out, $error);

print_r($out);

called by

/usr/bin/php /home/folder/folder/script.php
like image 176
Robbie Avatar answered Nov 07 '22 21:11

Robbie