Unix/Linux Go Back    

Gentoo Gentoo Linux is a versatile and fast, completely free Linux distribution geared towards developers and network professionals.

cpu%/mem% usage, scripting, dzen2: howto learn bash the hard way


Thread Tools Search this Thread Display Modes
Old Unix and Linux 08-17-2008   -   Original Discussion by broli
broli's Unix or Linux Image
broli broli is offline
Registered User
Join Date: Dec 2007
Last Activity: 23 July 2014, 5:32 PM EDT
Location: Argentina
Posts: 219
Thanks: 0
Thanked 0 Times in 0 Posts
i have been reading about how to sort arrays. and now i understand why you did this

NR > 5 { mem[$12] = $10; }

but the problem is, how do i print the array index ?
i need $12 later on

until i can fix that "retieval" of the value, i dont see how to integrate the memory calculation into the next awk

altho i have integrated the cpu part in one awk, and only that, nor more exhos Linux

im gettign there Linux


while :
	top -b -n 1 > /tmp/salidatop
	awk '	NR==3 { printf "^fg(green)CPU %2.f%% ** ",$5 } \
		NR==8, NR==12 { printf "[^fg(cyan)%s(^fg(red)%s^fg(green)]--",$12,$9 } \
		END { print ">>" } ' /tmp/salidatop

	memper=$(awk 'NR==4 { total=$2; free=$6; buffers=$8}
			NR==5 { cached=$8 }

			END {   
	        	sub( "k","",total)
		        sub( "k","",free)
			sub( "k","",buffers)
			sub( "k","",cached)

			suma = free + buffers + cached
			porcentaje = (suma * 100) / total
			printf "%2.f\n",porcentaje }' /tmp/salidatop)

	echo -n "^fg(green)MEM $memper% ** "
	sort -r -n -k10 /tmp/salidatop | awk 'NR<=5 { printf "[^fg(cyan)%s(^fg(red)%s^fg(green)]--",$12,$10 } \
						END { print ">>" } ' 

	sleep 4

done | dzen2 -ta l -u -l 1 -x 20 -y 710 -w 660 -e 'onstart=lower,uncollapse'

Sponsored Links

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Should I learn bash scripting or is it going obsolete? KalEl Shell Programming and Scripting 9 10-31-2010 07:53 PM
HOWTO - Total memory and CPU usage ... without top? newbie_01 UNIX for Dummies Questions & Answers 2 09-21-2010 01:16 AM
Any book to learn perl scripting vkvishwakarma6 Shell Programming and Scripting 5 02-24-2010 02:05 AM
Help- To learn shell scripting tj23 Shell Programming and Scripting 2 06-20-2008 07:10 AM
newbie: way to learn more about server's resource usage blakekr UNIX for Dummies Questions & Answers 2 05-20-2008 12:43 AM

All times are GMT -4. The time now is 01:54 PM.