0

This will be a very dumb question to the gurus I'm guessing but here goes.

I am trying to keep track of the number of threads on my system and I need to add timestamp somewhere with each output.

Here is my current command to check number of threads :

watch -n1 'ps -eLo pid,cmd,nlwp | wc -l >> test.txt'

I would like the timestamp to be added on each line in test.txt as the number of threads gets written

How do I get the output to look like 2020-12-14 07:08:10 5431 (where 5431 is the number of threads) ?

Chapo
  • 203
  • Use ts or one of the many options involving date from the dupe – muru Dec 14 '20 at 03:29
  • I am certain that there are ones out there a lot cleaner than this one, but it seems to work: watch -n 1 'printf "$(date +%F" "%T" ")" >> test.txt; ps -eLo pid,cmd,nlwp | wc -l >> test.txt' – Terrance Dec 14 '20 at 03:29
  • printf can handle date format printf '%(%F %T)T %s\n' now "$(ps -eLo pid,cmd,nlwp | wc -l)", but I think like muru ts is a good choice –  Dec 14 '20 at 17:04

0 Answers0