Linux script for remove the contents of tmpfs


I want to create a script that removes the contents of tmpfs (/docroot/shoeshop/var/session &cache &log). The script should send an email, warning when tmpfs reaches the 75%, and remove the contents of tmpfs session &cache &log and send another email) at 90%.
cat /etc/fstab
proc            /proc           proc    defaults        0       0
/dev/md0        /               ext3    defaults,noatime,errors=remount-ro 0       1
/dev/sda1       none    swap    sw      0       0
/dev/sdb1       none    swap    sw      0       0
tmpfs           /docroot/shoeshop/var tmpfs rw,size=2G 0 0

Actually i have this in my crontab;

30 1 * * 0-3 find /docroot/shoeshop/var/session/  -iname "sess_*" -exec rm {} \;
30 1 * * 0-3 find /docroot/cshoeshop/var/cache/* -mtime +7 -exec rm {} \;
30 1 * * 0-3 find /docroot/shoeshop/var/log/* -mtime +7 -exec rm {} \;

VMWAREit security administratorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

du -ks /docroot/shoeshop/var will give you the data of the total usage.
use df -k to get a listing of the file system.
using cut/awk you can extract the %used.
and generate an email.
alternatively, instead of having three cron jobs, you can have one that is a perl script the will perform the same information.
VMWAREit security administratorAuthor Commented:
Hi Arnold,

I don't know  bash scripting, could you help me?.

Thanks in advance
You may have to adjust the element from awk if the length of your mount point causes the percentage used to be the sixth element versus the fifth.
tempfs=`/usr/bin/df -k | /bin/grep shoeshop| /bin/grep -v '%' | /usr/bin/awk ' { print $5 } '`

if [ "$tempfs" -ge '75' } ; then
 echo "treshold reached"
 [ ! -e "flag_file" ] && echo "To:

" | /usr/bin/sendmail -oi -t 
/bin/touch flag_file
elsif  [ "$tempfs" -ge '90' } ; then
  echo "tempfs is more than 90% in use"
  [ -e "flag_file" ] && echo "To:

Message " | /usr/bin/sendmail -oi -t 
unlink flag_file
#run your find commands here

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.