I am monitoring my cloud server so I wrote a script using top
command and stored the output file in single line with date , but its not working
(date)&&(top -n 1 | grep firefox) >> filename.txt
Kindly help me
I am monitoring my cloud server so I wrote a script using top
command and stored the output file in single line with date , but its not working
(date)&&(top -n 1 | grep firefox) >> filename.txt
Kindly help me
The following command should work:
((date | tr -d "\n")&&(top -b -n 1 | grep firefox)) >> filename.txt
2 fixes:
I enclosed in parentheses the full command so that even the date
output is redirected to the file, the tr
part just removing the carriage return.
I use top
in batch mode -b
to get the full list of processes.
tr -d
means delete this character. here the carriage return. That way both the date and the result from the top command are on a single line
Sep 9, 2015 at 7:00
i think firefox will not always appear on the top output, so what about
((date) && (ps aux | grep firefox | grep -v grep)) >> filename.txt
It's the same info, in a different format, and you could always be sure that you will get firefox info if it's running.