Subject: 2 script to auto extend fs on aix

From: Robert Binkley (rbinkl@COMCAST.NET)
Date: Wed Dec 10 2003 - 20:56:12 EST


Subject: 2 script to auto extend fs on aix

> #!/bin/ksh

> ##########################################################################

> ##

> ##

> # Script : chk_space

> # Purpose: The script will run in cron and check space for the

> # destination and will perform an action in case the space

> # reach critical percentage.

> # I don't recommend to auto extend ,I will sure not do it. I prefer

> # to investigate why the file system got filled before I increase it.

> # On the other hand you can if,gust raw data you can increase on the fly

> # Then the dba can grow his database

> # This was written for Aix Only.

> ##########################################################################

> ##

> ##

> # set -vx

> DATA =" /data1

> /data2

> /data3

> /data4 "

>

> let AVRG=80 # The percentage that the script will check for

> ACTION=0

> DT=$(date)

>

> for STR in $(/bin/df -Ik/$DATA | grep -v "^Filesystem" | awk '{ print

> $4,

> $5, $6 }' | sed "s/ /:/g")

> do

> FS_DEST=$(echo $STR | awk -F : '{ print $3 }')

> let FR_SPACE=$(echo $STR | awk -F : '{ print $1 }')

> let USED=$(echo $STR | awk -F : '{ print $2 }' | cut -f1 -d%)

> if [[ $USED -gt $AVRG ]]

> then

> ACTION=1

> print "\nATTENTION: (Time stamp : $DT)" >> /tmp/message

> print "$FS_DEST is over $AVRG%, it is now at $USED% and

> still h

> ave $FR_SPACE KB free" >> /tmp/message

> fi

>

> # Add any required action if the file system is greater than the

> # average percentage AVRG

> if [ $ACTION = 1 ]

> then

> print "$FS_DEST file system size is increased by 1GB" >>

> /tmp/message

> chfs -a size=+2000000 $FS_DEST >> /tmp/message

> ACTION=0

> fi

>

> done

>

> # Mail the log file to SYSADMIN

> if [ -s /tmp/message ]

> then

> mail who_ever@whatever < /tmp/message

> /bin/rm /tmp/message

> fi

>

>

> ##########################################################################

> ########################################

> #!/bin/ksh

> #

> # 10/01;dwh v1.00: created

> #*************************************************************************

> ****

> # expandfs

> #*************************************************************************

> ****

> #

> # PURPOSE

> # Monitor the usage of a filesystem and if useage goes above 95%,

> # automatically increase the filesystem by 1 GB

> #

> # SYNTAX

> # expandfs filesystem

> #

> # OPTIONS

> # filesystem Name of the filesystem to monitor

> #

> # NOTES

> # Notes...

> #

> #*************************************************************************

> ****

> #

> trap "exit 1" 1 2 3 15

>

> COMMAND="$(basename $0)"

>

> VERSION="1.00"

>

>

> # * * * * * * * * * * * * * * * * MAIN * * * * * * * * * * * * * * * * *

> *

>

> # make sure user is root (uid 0)

> if (( $(id | sed -e 's/(.*$//' -e 's/^.*=//') != 0 )); then

> print -u2 "$COMMAND: only root can run this command"

> exit 1

> fi

>

> # check for proper usage

> if (( $# != 1 )); then

> print -u2 "usage: $COMMAND filesystem"

> exit 1

> fi

>

> FILESYSTEM="$1"

>

> # check to see if filesystem is mounted

> MOUNTED=$(mount | grep jfs | awk '{print $2}' | grep

> "^${FILESYSTEM}$")

>

> # error if filesystem is not mounted

> if [[ -z $MOUNTED ]]; then

> print -u2 "$COMMAND: error: filesystem $FILESYSTEM is not mounted"

> exit 1

> fi

>

> # see how full the filesystem is

> CAPACITY=$(df -Pk $FILESYSTEM | tail -1 | awk '{print $5}' | sed -e

> 's/%//')

>

> # done if capacity is less than 95%

> (( $CAPACITY < 95 )) && exit 0

>

> # get logical volume name

> LOGICAL_VOLUME=$(lsfs $FILESYSTEM | tail -1 | awk '{print $1}' | sed

> -e 's!/dev/!!')

>

> # get volume group name

> VOLUME_GROUP=$(lslv $LOGICAL_VOLUME | grep 'VOLUME GROUP:' | sed -e

> 's/^.*VOLUME GROUP: *//')

>

> # see how much space is available in the volume group

> FREE_SPACE=$(lsvg $VOLUME_GROUP | grep 'FREE PPs:' | sed -e 's/^.*(//'

> -e 's/ .*$//')

>

> # email an error message to root if there's not at least 1GB available

> if (( $FREE_SPACE < 1024 )); then

>

> (print "Subject: Not Enough Free Space To Increase Filesystem"

> print "From: $COMMAND\n"

> print "Filesystem ${FILESYSTEM} is ${CAPACITY}% full but"

> print "there is not enough available space in volume group"

> print "${VOLUME_GROUP} to increase the size by 1GB") |

> /usr/lib/sendmail root

>

> exit 1

> fi

>

> #####################################################################

> ## make sure the MAX LP setting is big enough to add another 1GB

> #####################################################################

>

> # get physical partition size

> PP_SIZE=$(lslv $LOGICAL_VOLUME | grep ' PP SIZE: ' | sed -e 's/^.* PP

> SIZE: *//' -e 's/ .*$//')

>

> # calculate the number of PP's in 1GB

> LPS_TO_ADD=$((1024 / $PP_SIZE))

>

> # get current number of PP's in this logical volume

> LPS=$(lslv $LOGICAL_VOLUME | grep '^LPs: ' | sed -e 's/^LPs: *//' -e

> 's/ .*$//')

>

> # add 1GB worth of PP's

> NEW_LPS=$(($LPS + $LPS_TO_ADD))

>

> # get the maximum number of LP's for this logical volume

> MAX_LPS=$(lslv $LOGICAL_VOLUME | grep '^MAX LPs: ' | sed -e 's/^MAX

> LPs: *//' -e 's/ .*$//')

>

> # increase the maximum number of logical partitions if necessary

> if (( $NEW_LPS > $MAX_LPS )); then

>

> chlv -x $NEW_LPS $LOGICAL_VOLUME

>

> # email an error message to root if chlv failed

> if (( $? != 0 )); then

>

> (print "Subject: Error Trying To Increase MAX LPs"

> print "From: $COMMAND\n"

> print "Filesystem ${FILESYSTEM} is ${CAPACITY}% full\n"

> print "MAX LPs (${MAX_LPS}) for volume group ${VOLUME_GROUP}

> will"

> print "not allow me to increase the filesytem by 1GB"

> print "and attempts to increase MAX LPs have failed") |

> /usr/lib/sendmail root

>

> exit 1

> fi

>

> fi

>

>

> #####################################################################

> ## increase the filesystem by 1GB (2097152 blocks)

> #####################################################################

>

> # get current size of filesystem in 512 Kb blocks

> CURRENT_SIZE=$(df $FILESYSTEM | tail -1 | awk '{print $2}')

>

> # add 1GB (1GB = 2097152 blocks)

> NEW_SIZE=$(($CURRENT_SIZE + 2097152))

>

> # increase the filesystem by 1GB

> chfs -a size=$NEW_SIZE $FILESYSTEM

>

> if (( $? == 0 )); then

>

> # convert size in blocks to size in KB

> NEW_SIZE=$(($NEW_SIZE / 2))

>

> (print "Subject: Size Of ${FILESYSTEM} Has Been Increased"

> print "From: $COMMAND\n"

> print "Filesystem ${FILESYSTEM} was ${CAPACITY}% full\n"

> print "An additional 1GB has been added to this filesystem\n"

> print "Size of filesystem is now $NEW_SIZE Kb") | /usr/lib/sendmail

> root

>

> exit 0

>

> else

>

> (print "Subject: Error Trying To Increase Size Of ${FILESYSTEM}"

> print "From: $COMMAND\n"

> print "Filesystem ${FILESYSTEM} is ${CAPACITY}% full\n"

> print "Attempts to increase the filesystem by 1GB have failed") |

> /usr/lib/sendmail root

>

> exit 1

>

> fi

Robert Lee Binkley
5009 SIlver Oak
Sherwood, Ar 72120
rbinkl@comcast.net

Contract Rate 1099 50.00 per hour
                      W-2 41.00 per hour



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:17:24 EDT