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


Login or Register to Reply

 
Thread Tools Search this Thread
# 15  
Old 08-17-2008
i have been reading about how to sort arrays. and now i understand why you did this
Code:
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 Smilie

im gettign there Smilie
Code:
#!/bin/bash

while :
do
	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'

Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Learn bash shell scripting lg123 UNIX for Dummies Questions & Answers 3 09-05-2013 12:56 AM
Help creating a timestamp script to record mem usage vpundit Shell Programming and Scripting 2 06-29-2012 12:41 PM
Command to find total cpu and mem aish11 Shell Programming and Scripting 5 01-27-2012 01:00 AM
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
Help with bash script - Need to get CPU usage as a percentage graysky Shell Programming and Scripting 3 11-25-2009 10:23 AM
How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..? laknar AIX 3 07-16-2009 06:35 AM
Multi CPU Solaris system shows 100% CPU usage. mahive Solaris 4 05-27-2009 04:52 PM
Checking mem usage at specific times in a program pl4u UNIX for Advanced & Expert Users 2 04-05-2009 06:26 PM
current CPU usage, memory usage, disk I/O oid(snmp) S_venkatesh Solaris 2 12-13-2008 06:19 AM
how can I find cpu usage memory usage swap usage and logical volume usage alert0919 HP-UX 3 12-02-2008 02:38 PM
Linux Mem Usage new2ss Linux 1 10-10-2007 11:04 PM
High Mem & Cpu Utilisation gautamatul82 Linux 1 06-24-2006 12:53 PM
Monitor CPU usage and Memory Usage Gajanad Bihani Programming 2 03-09-2005 07:35 AM
Difference in Mem usage ? shibz UNIX for Dummies Questions & Answers 1 02-24-2004 09:46 AM