sunhux
asked on
Capturing top 20 CPU processes in Linux to a file
Hi,
If I issue "nohup top > /tmp/top.txt"
it will give all sorts of characters in the top.txt file
Is there any way I can capture a proper text output
(with the timestamp but without the unnecessary headers)
for top 20 CPU processes every 3 secs?
ASKER
In fact "nohup top > /tmp/top.txt" would not work at all
ASKER
& the command below would prevent me from logoff the server:
top -d 3 -n 25000 -b > /var/tmp/top.txt
So I'll need something that allows me to logoff & it continues to capture
for that you need to use nohup and & both.
# nohup <script.sh> &
It this way it will run after log off as well.
# nohup <script.sh> &
It this way it will run after log off as well.
ASKER
& I just need the top 20 CPU consuming processes but my previous command
gave practically all processes
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Omar's command would crash due to " | head -20" & it
would run Ok if " | head -20" is removed :
"nohup top -d 3 -n 25000 -b | head -20 > /var/tmp/top.txt"
Upanwar script is missing looping 25000 times.
Wesly's script is missing 25000 loops too & there's a syntax error :
"while" should read "while [ 1 ] "
If you want to count it for 25000 time then It should work
#!/bin/bash
for (( c=1; c<=25000; c++ ))
do
ps -eo user,pcpu,pid,command | sort -r -k2 | head -21 >> /var/tmp/top20.txt
sleep 3
done
#!/bin/bash
for (( c=1; c<=25000; c++ ))
do
ps -eo user,pcpu,pid,command | sort -r -k2 | head -21 >> /var/tmp/top20.txt
sleep 3
done
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok
http://idolinux.blogspot.com/2008/08/see-your-top-ten-cpu-intensive.html