1832656 Members
3198 Online
110043 Solutions
New Discussion

script writing

 
Donna Powell
Advisor

script writing

I am trying to write a script that will allow me to monitor disk space on all my boxes. I am fairly new to script writing, but I can read scripts very well. My plan is to use diskinfo to give me the info that I need pertaining to each disk on the system. This is what I have done so far:
I have created a variable that holds all the rdsk names on the box, but now I need to execute the diskinfo command. My problem is my variable contains more then one drive and my diskinfo command will only run one character device at a time. What do i need to do to get the system to read my variable and run the diskinfo command to give me the info I need. Help, fairly new to script writing
9 REPLIES 9
A. Clay Stephenson
Acclaimed Contributor

Re: script writing

Hi Donna:

I don't think diskinfo is what you really want to be using but here's how to do it:

DISKS="/dev/rdsk/c0t6d0 /dev/rdsk/c1t6d0"
for DISK in ${DISKS}
do
diskinfo -v ${DISK}
done

A better way (or actually several) to monitor
disk usage can be found in this thread:
http://forums.itrc.hp.com/cm/QuestionAnswer/1,1150,0xcae0f9beca68d511abcd0090277a778c,00.html

Regards, Clay
If it ain't broke, I can fix that.

Re: script writing

you may want to try using bdf instead. my script runs a bdf then cuts out the 5th field and then sees if each one is greater than 90, if so it pages me. if you want the script let me know.
just do it!
James R. Ferguson
Acclaimed Contributor

Re: script writing

Hi Donna:

Try this:

#!/usr/bin/sh
DIR=/dev/rdsk
for D in `ls $DIR`
do
diskinfo $DIR/$D
done

...or...

#!/usr/bin/sh
DIR="c0t6d0 c1t1d0 c1t1d1"
for D in $DIR
do
diskinfo "dev/rdsk/$D"
done

Regards!

...JRF...
Donna Powell
Advisor

Re: script writing

James, Clay and Jennifer, thanks for your replys, James I used your suggestion and it worked just fine, but Clay I think your right diskinfo is not really giving me the info that I need. I am looking to get infomation on all of my harddrives configured on the system. I need to know how big each drive is and how much free space I have available to work with. We have several boxes and I then need to do a remsh to each box and get the same info. I also need to wean out EMC's Any other suggestions. thanks minor league script writer
James R. Ferguson
Acclaimed Contributor

Re: script writing

Hi Donna:

You need to look at the output from things like 'ioscan', 'pvdisplay' and 'vgdisplay'.

Based on what you are trying to assemble, a quick, free summary can be seen in the manifest file from Ignite.

I hope you are making Ignite recovery tapes of your systems (using 'make_tape_recovery') . If you are, everytime you do, you get a "free" configuration report, including a very nice summary of your LVM configuration. Look at:

/var/opt/ignite/recovery/latest/manifest

...JRF...
Rob Smith
Respected Contributor

Re: script writing

Hi, if you want a script that will notify you when disk usage reaches a certain level then try:
#!/usr/bin/sh
##

bdf | grep -iv filesystem | awk '{print $6 " "$5}' | while
read LINE; do
PERC=`echo $LINE | cut -d "%" -f1 | awk '{ print $2 }'`
if [[ $PERC -gt 90 ]]; then
echo "${PERC}% ALERT!" | mailx -s "${LINE} on `hostname` is almost full" root
fi
done

exit

This will send an e-mail to root. Or if you a complete report on LVM, disks etc, then try the script that is attached. I believe it was written by an HP engineer. I think someone in the forums sent it to me, anyway, it is very complete, I run it on a monthly basis. Hope this helps.

Rob


Learn the rules so you can break them properly.
Seth Hollist
Occasional Advisor

Re: script writing

Have any of you tried using free web based monitoring tools with e-mail and pageing fetures, such as Big Brother (bb4.com).
There's always room for improvment
Shahul
Esteemed Contributor

Re: script writing


Hi

I have a script here, That I am writng here, which will ask a vg name then U will have to type the VG name. Then it will list the diskinfo of all PVs in that VG.

echo "Enter the VG"
read vg
vgdisplay -v /dev/$vg | grep /dev/dsk | awk '{print$3}' > file1
sed 's/dsk/rdsk/' file1 > file2
>file3
while grep /dev file2 > /dev/null
do
diskinfo `cat file2 | line` >> file3
cat file2 | grep -v `line` > file2
done
cat file3

Please check up this will do or not.


Best of luck

Shahul

Paula J Frazer-Campbell
Honored Contributor

Re: script writing

Hi Donna

This is a script I use,
Author was Adreas Voss.
I called it space check and cronned it to run twice a day.


It was posted by Andreas some time ago and does the job very well.

HTH

Paula

----------------------CUT HERE-------------------------
#!/sbin/sh
# Check server diskspace
# check with bdf filesystems on multiple servers
# Ensure server is in /etc/hosts file
# (c) hpux@voss2000.de 2000-10-11
# this script can/should be run with non root user
# for remote shell there has to be set permission in $HOME/.rhosts
# at the remote system(s)
# the script uses /tmp/bdfcheck directory to store percentage of
# each filesystem for history to avoid multiple message generation

MAILUSER="root;fred@company.com " # <-- put here the email address for sending
HOSTLIST="N-0 k1 k2" # HIGHWATERMARK=95 # max percentage of filesystem usage

[ ! -d /tmp/bdfcheck ] && mkdir /tmp/bdfcheck

for host in $HOSTLIST
do
{
if [ $host = $(hostname) ]
then
bdf -t hfs -t vxfs -l
else
remsh $host bdf -t hfs -t vxfs -l
fi
}|tail +2 |awk -vhost=$host '{
if(length(fs)>1)
fs=fs $0;
else
{
if(NF == 1)
{
fs=$1;
continue;
}
else
fs=$0
}
printf("%-10s: %s\n",host,fs);
fs="";
}'
done |
awk -vmax=$HIGHWATERMARK -vdate="`date`" 'BEGIN{first=1}
{
percent=$7;
hostname=$1;
filesystem=$NF;
gsub("/","_",filesystem);
sub("%","",percent);
percent=sprintf( "%d",percent);
histfile="/tmp/bdfcheck/" hostname filesystem;
getline oldpercent close(histfile);
print percent >histfile;
line=$0;
if(percent > oldpercent && percent > max)
{
if(first==1)
{
printf("%s\n\nFilesystems with more than %d%% usage:\n \n",date,max);
printf("%-10s Filesystem kbytes used avail %%used Mounted on\n","Hostname");
first=0;
}
printf("%s\n",line);
}
}' >/tmp/bdf_$$

if [ -s /tmp/bdf_$$ ]
then
cat /tmp/bdf_$$ | mailx -s 'FILESYSTEMS WARNING' $MAILUSER
fi
rm -f /tmp/bdf_$$
cd /tmp/bdfcheck
rm *
-------------------------cut here -------------------
If you can spell SysAdmin then you is one - anon