Tuesday, February 12, 2013

Script to add and mail bdf output in GB in excel frmt HP UX

Hi Friends,

Sometimes, we need o/p of BDF from our servers with below specification :-

1. We want to add o/p of BDF and then send the output to an excel sheet through mail.
2. Adding the allocated and used space is a requirement to check resource utilization measuremnet.
3. BDF o/p calculation with (output in GB) and adding the o/p as well and then seding through mail in excel format.
4. To avoid lengthy process of logging into each servers and doing all maths, will consume lot and lot of time. if servers are more then we may need to give number of days or assign a particular guy of looking into this.
5. this script can be modified on the basis of requiremnent.
6. so with the help of google friend, and some twist. Below script into existence. LOL.

SCRIPT for BDF o/p on mail in GB in excel format.......

#!/bin/sh
echo "**************" > /tmp/resource.csv
echo "Resource Utilization and Uptime" >> /tmp/resource.csv
echo "**************" >> /tmp/resource.csv
echo "Total Space allocated in GB" >> /tmp/resource.csv
bdf -l | awk '{if(NF==1){l=$0;getline;sub(" *"," ");print l$0}else print}' |awk '{print $2/1048576 }' | awk '{sum += $1} END {print sum}' >> /tmp/resource.csv
echo "Total Space Used in GB" >> /tmp/resource.csv
bdf -l | awk '{if(NF==1){l=$0;getline;sub(" *"," ");print l$0}else print}' |awk '{print $3/1048576 }' | awk '{sum += $1} END {print sum}' >> /tmp/resource.csv
echo "uptime report " >> /tmp/resource.csv
uptime >> /tmp/resource.csv
/usr/bin/uuencode /tmp/resource.csv /tmp/resource.csv |mailx -m -s " Resource utilization and Uptime Report" xyz@xyz.com

What above script is doing :-

a. echoing thing is just to give information about what command will provide.
b. bdf output is followed with awk to select only allocated and used column of bdf o/p. using separate line for both need.
c. resource.csv will generate the file in excel format.
d. awk '{if(NF==1){l=$0;getline;sub(" *"," ");print l$0}else print}' :- this is being used to print the o/p in a line so that confusion by command of space and blank line can be avoided.
e.  print $2/1048576 :- this is being done to convert value into GB.
f. ">> " sign is appending the o/p value in every command and cascading.
g. uuencode is being used to attach file and mailx is for sending mail on any email ID.
h. uuencode and mailx combination is being used to have attachment from server itself.


will add more into it.

Thanks for every visit
Love All and Love Sharing
Amit Chopra

1 comment:

Unknown said...

Amit, useful script, thank you. How would it be modified to exclude any storage that is part of /dev/vg00? In my case I'm not interested in internal storage (vg00), only external storage (anything else). Thanks in advance for your help.