D
D
Dmitry2014-05-19 08:40:13
linux
Dmitry, 2014-05-19 08:40:13

Error: TERM environment variable not set?

Good day!
There is a bash script in which the command is executed in one of the places

echo `top -n1 | grep Cpu | awk '{print $2}'` >> $PWD'/logs/meter-proc.log'

The line writes the current processor load in % to the file.
When calling via the ssh console, there are no problems - everything is correct. But the script must be called from PHP. I do it like this:
$descriptorspec = array(0 => array("pipe", "r"),
 1 => array("pipe", "w"),
2 => array("file", "logs/error-output.log", "a"));

$process = proc_open(__DIR__.'/meter.sh', $descriptorspec, $pipes);

The process starts correctly, but gives the error "TERM environment variable not set" exactly at the place where top was called. Understood that the given variable is empty.
I tried to manually write xterm, linux values ​​​​in TERM, but in any of these cases, the "top failed tty get" error starts to come out.
Strictly speaking: how to fix the error with TERM when called from PHP, or how else to get the current CPU load in% bypassing the use of top?
All action takes place on the Ubuntu server.
Thank you very much in advance!
PS Before asking a question, I tried to ask Google for a long time, but without success :(

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
jcmvbkbc, 2014-05-19
@Difull

top -b -n 1

A
Alexey Cheremisin, 2014-05-19
@leahch

To run top, you must use a pseudo/or/terminal (/dev/(p)tty), otherwise the termcap library will not be able to run on it. How to start a process in php using pseudo-terminal - I don't know.
Or install sar (sysstat) and use the mpstat utility.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question