[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 570
  • Last Modified:

Linux script for remove the contents of tmpfs

Hi,

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 {} \;

Thanks!!!
0
VMWARE
Asked:
VMWARE
  • 2
1 Solution
 
arnoldCommented:
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.
0
 
VMWAREit security administratorAuthor Commented:
Hi Arnold,

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

Thanks in advance
0
 
arnoldCommented:
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.
#!/bin/bash
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:
From: 
Subject:

message
" | /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:
From:
Subject:

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

Open in new window

0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now