Operating System - HP-UX
1838676 Members
4250 Online
110128 Solutions
New Discussion

shell scripts email unix server memory utilization

 
SOLVED
Go to solution
adhyapak
Occasional Contributor

shell scripts email unix server memory utilization

Hi all,

I need to send the Server Memory Utiliztion (%) statistics.We have HP Unix Server. Glance installed.

Can we have shell script which will get the above statistics and send a mail.

thanks,
Avinash
a2avin@gmail.com
9 REPLIES 9
Ivan Krastev
Honored Contributor

Re: shell scripts email unix server memory utilization

See some examples - http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1057532


Just choose one , which is best for you and add crontab entry for that script to mail results.


regards,
ivan
adhyapak
Occasional Contributor

Re: shell scripts email unix server memory utilization

thanks.

But is there any way we can mail across..
Oviwan
Honored Contributor
Solution

Re: shell scripts email unix server memory utilization

hy

to mail it use the script you want:
i.e. swapinfo -t | awk '/^total/ {printf "%2.2f GiB Avail\t%2.2f GiB Free\n",$2/1048576,$4/1048576}' | sendmail blah@blubb.bleh

Regards
Yogeeraj_1
Honored Contributor

Re: shell scripts email unix server memory utilization

hi,

once you have collected the desired information, you can forward it using the mail facility. e.g.

/usr/bin/uuencode $logfile "ServerMemUtil.txt"|mailx -m -s "`hostname`-Server Memory utilisation - `date`" $emailadd1

where $emailadd1=
$logfile=

hope this helps too!

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Raj D.
Honored Contributor

Re: shell scripts email unix server memory utilization

Abhyapak,

You only need to run glance in advisor only mode.And mailx the output,

Attached the script cpumem.sh and cpumem.syn for this purpose.

Enjoy and Cheers,
Raj.

" If u think u can , If u think u cannot , - You are always Right . "
Raj D.
Honored Contributor

Re: shell scripts email unix server memory utilization

Avinash,,

After generating the report you can get automated email by just putting a small script in the cron , with

# uuencode logfile.txt logfile.txt | mailx -s "Server-x cpu and memory usage report for `date ` " youremail@domain.com


Cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
shivan
Occasional Advisor

Re: shell scripts email unix server memory utilization

#!/bin/sh
/usr/sbin/swapinfo | grep memory | awk '{print $5}' | mailx -s "Memory Utilization from host xyz" yourid@yourdomain.com

Create above script with execute permission and update crontab.
Raj D.
Honored Contributor

Re: shell scripts email unix server memory utilization

Avinash,

Btw, which memory utilization are you looking for , Physical memory or Virtual Memory utilization ?

Cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
Geoff Wild
Honored Contributor

Re: shell scripts email unix server memory utilization

I like the output of the memdetail c program:

$ /usr/local/bin/memdetail

Memory Stat total used avail %used
physical 10080.0 8445.1 1634.9 84%
active virtual 7313.6 1179.7 6133.9 16%
active real 5818.8 569.8 5248.9 10%
memory swap 7707.8 1715.5 5992.2 22%
device swap 28080.0 6852.3 21227.7 24%

Just use the native HPUX compiler to compile the attached.

Then you can run it from cron say every hour?

/usr/local/bin/memdetail | mailx -s "memdetail `/usr/bin/date`" you@yourdomain.com

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.