Results 1 to 4 of 4
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 ...
- 04-20-2011 #1Just Joined!
- Join Date
- Jan 2010
- Posts
- 6
script to tar up files when a partition hits a certain use percentage
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:
So, when the cronjob sees that the Use% is >= 90%, it would kick off the tar script...if not above 90%, it closes.Filesystem Size Used Avail Use% Mounted on
/dev/sda5 7.5G 331M 6.8G 5% /var
Thanks.
- 04-20-2011 #2Code:
#!/bin/bash SPACE=`df -h | grep var | awk '{print $5}' | sed 's/%//g'` if [ $SPACE -ge 90 ]; then # tar files else # No tarring fi exit 0
- 04-20-2011 #3
Hmm, I donīt think hunter_thomīs script will work as a cronjob (sorry, no offence and yes: I see that the script is meant as a skeleton
), because there is no guarding against concurrent runs. Depends solely on the cron schedule.
A better approach might be to use the built-in logrotate and/or disk free options of auditd
auditd.conf: audit daemon config file - Linux man pageYou must always face the curtain with a bow.
- 04-20-2011 #4Just Joined!
- Join Date
- Jan 2010
- Posts
- 6
Thank you both for the responses. (and sorry this isn't in the correct forum, but I have sent a message to get the thread moved to the appropriate forum).
Anyhow, this is what I got from another site that I was browsing and it works for what I need it to do.
It looks very similar to the script above. But again, thanks for the responses!#!/bin/bash
a=$( df -h | grep -i "var" | awk '{print $5}' | awk 'sub(".$","")')
if [ $a -ge 90 ]
then
sh /var/log/blah_script.sh
else
exit
fi


Reply With Quote