Today (Saturday) We will make some minor tuning adjustments to MySQL.

You may experience 2 up to 10 seconds "glitch time" when we restart MySQL. We expect to make these adjustments around 1AM Eastern Daylight Saving Time (EDT) US.

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

Login or Register to Reply

Thread Tools Search this Thread
# 15  
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 Smilie

im gettign there Smilie

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'

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
I do not know shell scripting. But at work place, I have got an in and out shell scripting task. I just need to understand a very big script. Is there any tool in which I can place the script and it can tell me the meaning of the whole script?... UNIX for Dummies Questions & Answers
UNIX for Dummies Questions & Answers
Should I learn bash scripting or is it going obsolete?
Hi folks, I'm a CS students enrolled in a sysadmin class where we've been covering bash scripting for the past few weeks. I have prior knowledge in java, c++, c#, python,and some scripting languages like w/c# and php. This bash stuff seems pretty neat and a bit different than what I am...... Shell Programming and Scripting
Shell Programming and Scripting
HOWTO - Total memory and CPU usage ... without top?
Hi all, Is it possible to get total memory usage and free memory usage without top? By Googling I found for total memory usage, use vmstat, for CPU, use mpstat, for disk I/O use iostat, is this correct? Will using sar gives the same result as ALL of these three (3) commands? What about if I...... UNIX for Dummies Questions & Answers
UNIX for Dummies Questions & Answers
Help with bash script - Need to get CPU usage as a percentage
I'm writing a bash script to log some selections from a sensors output (core temp, mb temp, etc.) and I would also like to have the current cpu usage as a percentage. I have no idea how to go about getting it in a form that a bash script can use. For example, I would simply look in the output of...... Shell Programming and Scripting
Shell Programming and Scripting
how can I find cpu usage memory usage swap usage and logical volume usage
how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to...... HP-UX
CPU_REBOOT(9)						   BSD Kernel Developer's Manual					     CPU_REBOOT(9)

cpu_reboot -- halt or reboot the system
#include <sys/reboot.h> void cpu_reboot(int howto, char *bootstr);
The cpu_reboot() function handles final system shutdown, and either halts or reboots the system. The exact action to be taken is determined by the flags passed in howto and by whether or not the system has finished autoconfiguration. If the system has finished autoconfiguration, cpu_reboot() does the following: 1. Sets the boothowto system variable (see boothowto(9)) from the howto argument. 2. If this is the first invocation of cpu_reboot() and the RB_NOSYNC flag is not set in howto, syncs and unmounts the system disks by calling vfs_shutdown(9) and sets the time of day clock by calling resettodr(9). 3. Disables interrupts. 4. If rebooting after a crash (i.e., if RB_DUMP is set in howto, but RB_HALT is not), saves a system crash dump. 5. Runs any shutdown hooks by calling pmf_system_shutdown(9). 6. Prints a message indicating that the system is about to be halted or rebooted. 7. If RB_HALT is set in howto, halts the system. Otherwise, reboots the system. If the system has not finished autoconfiguration, cpu_reboot() runs any shutdown hooks by calling pmf_system_shutdown(9), prints a message, and halts the system. If RB_STRING is set in howto, then the parameter bootstr is passed to the system boot loader on some ports.
boothowto(9), dumpsys(9), pmf_system_shutdown(9), resettodr(9), vfs_shutdown(9)
February 11, 2010 BSD

Featured Tech Videos