shell script to alert cpu memory and disk usage help please


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script to alert cpu memory and disk usage help please
# 1  
Old 09-22-2011
shell script to alert cpu memory and disk usage help please

Hi all

can any one help me to script monitoring
CPU load avg when reaches threshold value

and disk usage if it exceeds some %
tried using awk but when df -h out put is in two different lines awk doesnt work for the particular output in two different line ( output for df -h is in two lines when the filesystem is in lvm or the path is larger )
# 2  
Old 09-22-2011
can you paste the awk code yo tried? may be we can help to modify it...

--ahamed
# 3  
Old 09-22-2011
Quote:
Originally Posted by ahamed101
can you paste the awk code yo tried? may be we can help to modify it...

--ahamed
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ if( $4 < 10 ) print $5 " warning " $1 }'
# 4  
Old 09-22-2011
Code:
root@bt:~# df -H
Filesystem             Size   Used  Avail Use% Mounted on
/dev/sda4               15G   7.6G   5.8G  57% /
none                   1.1G   349k   1.1G   1% /dev
none                   1.1G    25k   1.1G   1% /dev/shm
none                   1.1G    99k   1.1G   1% /var/run
none                   1.1G      0   1.1G   0% /var/lock
none                   1.1G      0   1.1G   0% /lib/init/rw
/dev/sda7               61G    36G    25G  60% /media/Utils
/dev/sda5               17G   3.1G    14G  19% /media/Dev
/dev/sda6               38G    12G    26G  32% /media/New Volume
/dev/sda1               32G    15G    17G  47% /media



df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ if( 100-$5 < 10 ) print $6  "  warning " $1 }'

this will check if available is < 10 and report the warning. What is the exact condition you want to check?

--ahamed
# 5  
Old 09-22-2011
Quote:
Originally Posted by ahamed101
Code:
root@bt:~# df -H
Filesystem             Size   Used  Avail Use% Mounted on
/dev/sda4               15G   7.6G   5.8G  57% /
none                   1.1G   349k   1.1G   1% /dev
none                   1.1G    25k   1.1G   1% /dev/shm
none                   1.1G    99k   1.1G   1% /var/run
none                   1.1G      0   1.1G   0% /var/lock
none                   1.1G      0   1.1G   0% /lib/init/rw
/dev/sda7               61G    36G    25G  60% /media/Utils
/dev/sda5               17G   3.1G    14G  19% /media/Dev
/dev/sda6               38G    12G    26G  32% /media/New Volume
/dev/sda1               32G    15G    17G  47% /media



df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ if( 100-$5 < 10 ) print $6  "  warning " $1 }'

this will check if available is < 10 and report the warning. What is the exact condition you want to check?

--ahamed
yeah this works if the output is

like
/dev/sda5 17G 3.1G 14G 19% /media/Dev
/dev/sda6 38G 12G 26G 32% /media/New Volume
/dev/sda1 32G 15G 17G 47% /media
but where as if the out put is something like

/dev/mapper/vol00-lvabcdef
17G 3.1G 14G 19% /media/Dev
/dev/sda6 38G 12G 26G 32% /media/New Volume
/dev/sda1 32G 15G 17G 47% /media

this mismatches $5 and $6 so the out put varies
# 6  
Old 09-22-2011
Try this...

Code:
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{if(NF<2){x=$0;getline;$0=x" "$0}} { if( 100-$5 < 10 ) print $6  "  warning " $1 }'

--ahamed
# 7  
Old 09-22-2011
Quote:
Originally Posted by ahamed101
Try this...

Code:
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{if(NF<2){x=$0;getline;$0=x" "$0}} { if( 100-$5 < 10 ) print $6  "  warning " $1 }'

--ahamed
will try this
hopefully this works thanx a lot bro

will update tomoro
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with Shell script that monitors CPU Usage

I'm a newbie to shell scripting, I was given this script to modify. This script that monitors when CPU Usage is too high based off the top command. The comparison is not working as it should. Its comparing a decimal to a regualar interger. When it send me an email, it send an email and ignores the... (21 Replies)
Discussion started by: mhannor
21 Replies

2. Shell Programming and Scripting

Shell script for logging cpu and memory usage of a Linux process

I am looking for a way to log and graphically display cpu and RAM usage of linux processes over time. Since I couldn't find a simple tool to so (I tried zabbix and munin but installation failed) I started writing a shell script to do so The script file parses the output of top command through... (2 Replies)
Discussion started by: andy_dufresne
2 Replies

3. Shell Programming and Scripting

Get the memory and cpu usage

what is the best way to get the memory and cpu usage of a process on any system? this is relatively simple. however, i'm looking for a unified method that would work on linux, sunos, hpux, aix. ps -ef | egrep myprocess | awk '{print $4}' ---> there could be several instances of 'myprocess'... (3 Replies)
Discussion started by: SkySmart
3 Replies

4. Shell Programming and Scripting

help in high memory usage alert script

can any one please help me to shell script high memory usage alert (6 Replies)
Discussion started by: robo
6 Replies

5. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

6. Solaris

current CPU usage, memory usage, disk I/O oid(snmp)

Hi, I want to monitor the current cpu usage, monitor usage , disk I/o and network utlization for solaris using SNMP. I want the oids for above tasks. can you please tell me that Thank you (2 Replies)
Discussion started by: S_venkatesh
2 Replies

7. HP-UX

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... (3 Replies)
Discussion started by: alert0919
3 Replies

8. UNIX for Dummies Questions & Answers

cpu, memory and virtual memory usage

Hi All, Does anyone know what the best commands in the UNIX command line are for obtaining this info: current CPU usage memory usage virtual memory usage preferably with date and time parameters too? thanks ocelot (4 Replies)
Discussion started by: ocelot
4 Replies

9. Programming

CPU usage and memory usage

Please tell me solaris functions/api for getting following information 1- Function that tells how much memory used by current process 2- Function that tells how much memory used by all running processes 3- Function that tells how much CPU is used by current process 4- Function that tells how... (1 Reply)
Discussion started by: mansoorulhaq
1 Replies

10. Programming

Monitor CPU usage and Memory Usage

how can i monitor usages of CPU, Memory, Hard disk etc. under SUN Solaries through a c program or java program i want to store that data into database so i can show it graphically thanks in advance (2 Replies)
Discussion started by: Gajanad Bihani
2 Replies
Login or Register to Ask a Question