Register
It is currently Mon Oct 20, 2014 2:02 am

script to tar up files when a partition hits a certain use p


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Tue Apr 19, 2011 11:12 pm   

Joined: Tue Apr 19, 2011 11:01 pm
Posts: 36
Hello. First time here. Site looks really cool, with lots of great info. However, I need some scripting help:

In a nutshell:

I am in need to create a script that queries how large a partition is and when it hits a certain percentage (say 90%) it will execute another script that tars up certain files (or they could just be part of the same script). I would create a cronjob that runs this script once a day.

I have the script that tars up the files I need, sets permissions, etc. (btw, the files in question are audit logs). I just need the part that runs something like a df -h and takes the use percentage of the /var partition in that query and if that percentage is greater than/ equal to 90%, it kicks off the tar script.

Here is a sniplet of the df -h with just the /var partition shown:

Quote:
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 7.5G 331M 6.8G 5% /var

So, when the cronjob sees that the Use% is >= 90%, it would kick off the tar script...if not above 90%, it closes.

Thanks.


Top
 Profile  
 PostPosted: Wed Apr 20, 2011 6:45 am   

Joined: Tue May 18, 2010 7:08 am
Posts: 5
Hi,
the script u have asked may be like this.

#!/bin/bash
a=$( df -h | grep -i "var" | awk '{print $5}' | awk 'sub(".$","")')
if [ $a -ge 90 ]
then
exit
else
echo "Run Tar Script" # you may put the path of tar script here
fi


Top
 Profile  
 PostPosted: Wed Apr 20, 2011 8:04 am   

Joined: Tue Apr 19, 2011 11:01 pm
Posts: 36
Thanks! I'll give this a try.


Top
 Profile  
 PostPosted: Wed Apr 20, 2011 9:22 am   

Joined: Tue Apr 19, 2011 11:01 pm
Posts: 36
arvind.lotus,

I wanted to relay that I tried your recommendation and it works like a charm (I just switched the script path and exit around so it would run the script if it is >= 90% vs. exiting).

Thanks again!


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP