I am no arTist, but it works…

Hey, I like to script as much as the next guy, but I have always wondered why as a UNIX/Linux Admin/Engineer there are so many “similar” instances of issues and a plethora of examples on-line, yet very few, if any, complete (and functionally tested) interactive automated programs (if I don’t call it a program, even though it is not a “program,” it remains a script and we are stuck in a loop).  Anyway, much of what I do and I suspect what you do as well if you are reading this, kinda needs to be done pretty fast… ya know on the fly and it is quite repetitious.  So why not have a tool kit so to speak to perform these recurring tasks, instantly?  In a previous post I listed my Zimbra maildrop checker… this is in the same vein, however that was just a tool to discover information and then you have to manually execute the fix.  This one does it all for you and asks only a few questions.  I don’t know… maybe I am barking up the wrong tree here.  I guess in reality what I am trying to make is a command line Webmin?  Even though I love Webmin, I still cannot give up the command line…. LOL.  Hmmm… maybe I should just learn Perl and make these things FOR Webmin… Below is a little ditty to reduce an LV then extend another LV with the realized free PE.

# Filesystem resize:
# for some filesystem to be reduced to grow another filesystem(s)
df -h
echo “Enter the filesystem you are unmounting, including the ‘/'”
read unmountfs
fuser -mv $unmountfs # <– or whatever fs you are unmounting
for i in `fuser -mv $unmountfs|grep -v PID`; do kill -9 $i; done
read -p “If this looks OK, Press any key to continue.”
lvol=`df -H $unmountfs|grep -v $unmountfs|grep -v File`
umount $unmountfs
sleep 1
echo “Using the information above, answer the following questions…”
sleep 2
e2fsck -f $lvol
echo “Enter the NEW reduced size of the lv; i.e. 2G, 200M, etc…”
read newsize
resize2fs $lvol $newsize
lvreduce -L $newsize $lvol
mount $unmountfs
# Now lets extend the other filesystem(s)
echo “Check your FREE PE now…”
vgdisplay |grep “Free  PE / Size”
df -h
freepe=`vgdisplay |grep “Free  PE / Size”`
echo “Enter the name of the full LV name you wish to extend”
read fullv
echo “Enter no more than `vgdisplay |grep “Free  PE / Size”|awk ‘{print $5}’` Physical Extents”
read PE
lvextend -l +$PE $fullv
echo “Now compare the original FREE PE to the new FREE PE”
echo $freepe
vgdisplay |grep “Free  PE / Size”
df -h

Please keep in mind that I have NOT written any logic into this one yet… so… If you f’ something up… you might be in trouble.  I guess I have taken into assumption that whomever is using this knows what I am doing and can at least make fun of my “less than Earth shattering” scripting…

I am no arTist (pronounced r-Tee-st), but it works. 🙂


, , , , , , , , , , , , , ,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: