2

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

1

The following command should work:

((date | tr -d "\n")&&(top -b -n 1 | grep firefox)) >> filename.txt

2 fixes:

  1. 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.

  2. I use top in batch mode -b to get the full list of processes.

  • hi sylvain what is the purpose for tr -d – job finatel Sep 9 '15 at 6:04
  • @jobfinatel 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 – Sylvain Pineau Sep 9 '15 at 7:00
0

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.

  • and i get a output for this terminal #!/bin/bash echo $(date) / $(top -b -n 1 | grep firefox)>> – job finatel Jul 13 '15 at 10:04
  • Now i run this script in my shell script now is working but i need some clarification how to i import the excell sheet – job finatel Jul 13 '15 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.