Sorry Guys, There must have been an error when copying and pasting the script last time. I copied it from my email and had the same problem. I also noticed a couple other errors and fixed them. I have tested this, mailed it to my self and copied to the server and ran it again. It should be good to go. Take care, Paul #!/bin/bash -x #################################################################### # FreeVSD Quota Notification Script # # # # Written by Paul Marshall <[EMAIL PROTECTED]> # # From Protelligence http://www.protelligence.com # # # # This file is subject to the terms and conditions of the GNU # # General Public License. # # # # Copyright (C) 2001 Protelligence. All rights reserved. # #################################################################### # This script is designed to work with the FreeVSD quota system. # It should be run from cron on a daily or hourly basis. # The script checks the quota for both the Virtual Server and # individual users. # The VS Check will check the quota for the Virtual Server and email the # administrator when the quota reaches two different notification levels. # If a Virtual server exceeds the quota, the script then mails the # host administrator. # The User Check will check the quota for each user that has a quota. # When the user's quota reaches or exceeds one of two notification levels, # both the user and the Virtual Server administrator will receive an # email. If the user exceeds their quota, the Virtual Server # administrator receives an email. # Set some variables PATH=/bin:/sbin:/usr/bin:/usr/sbin # Path to quotastats QUOTASTATS="/usr/sbin/quotastats" # Path to the mail program MAIL_PROG="/bin/mail" # The Warning Level # This is the warning level represented by a percentage of the total # quota. This is when the first notice is sent. (default is 80%) warn_level=0.80 # This a decimal percentage value # The Critical Level # This is the critical level represented by a percentage of the total # quota. This is when the second and last warning is sent. (default is # 90%) crit_level=0.90 # This is a decimal percentage value # The host administrator email address host_admin="[EMAIL PROTECTED]" #The Virtual Server vs=`hostname` # Automatically get hostname # The Virtual Server admin user vs_admin="admin" # Use the username or email address # OK, now we can start # Setup the mailing functions # Sends an email to the Virtual Server Administrator and the Host # Administrator when a Virtual Server reaches the quota limit. function mail_vs_over { sbj="$level: ${vs} has reached the disk quota limit" msg="\\nThe Virtual Server ${vs} has reached the disk quota limit. \ The max quota for this server is ${vs_max}K and the server is \ currently using ${vs_used}K.\\n\\n \ DATA IS CURRENTLY BEING LOST!\\n\\n \ Either clear some space on this server or increase the quota.\\n" echo -e ${msg} | ${MAIL_PROG} ${host_admin} -s "${sbj}" -c ${vs_admin}; } # Sends an email to the Virtual Server Administrator and the Host Administrator # when the server reaches one of the warning levels. function mail_vs_warn { sbj="${level}: ${vs} is over the quota limit" msg="\\nThe Virtual Server ${vs} is approaching the disk quota \ limit. The server has reached the ${level} level. The server is \ currently using ${vs_used}K of the ${vs_max}K quota. \\n\\n \ You can try the following solutions to correct the situation:\\n\\n \ 1. Consider deleting some old files or purging some log files.\\n\\n \ 2. See if you have users who are leaving excessive amounts of \ mail on the server. If so, set a quota limit for that user or \ ask them to purge the mail by removing the Leave Mail on Server \ option in their mail program.\\n\\n \ 3. Contact your host administrator to have the quota on your \ server increased. (There may be additional costs.)" echo -e ${msg} | ${MAIL_PROG} ${vs_admin} -s "${sbj}" -c ${host_admin}; } # Sends an email to the User and the Virtual Server Administrator when a # user reaches their quota limit. function mail_user_over { sbj="$level: ${user} has reached the disk quota limit" msg="\\n${user} has reached their disk quota limit. \ The max quota for this user is ${user_quota}K and the server is \ currently using ${user_used}K.\\n\\n \ DATA IS CURRENTLY BEING LOST!\\n\\n \ Either clear some space on this server or increase the quota.\\n" echo -e ${msg} | ${MAIL_PROG} ${vs_admin} -s "${sbj}" -c ${user}; } # Sends and email to the User and the Virtual Server Administrator when # the user has reached on of the warning levels. function mail_user_warn { sbj="${level}: ${user} is approaching the quota limit" msg="\\nYour user, ${user}, is approaching the disk quota \ limit. The user has reached the ${level} level. The user is \ currently using ${user_used}K of the ${user_quota}K quota. \\n\\n \ As a user, you may not have much control over this, however, there \ are a few things you can try. You can try the following solutions to \ correct the situation:\\n\\n \ 1. If you have access to your files on the server, consider deleting \ some old files or purging some log files.\\n\\n \ 2. Check your mail program settings. If you have the Leave Mail on Server \ option checked, uncheck it and try checking your mail. This should download \ the mail to your computer and delete it from the server. \\n\\n \ 3. Contact your host administrator to have the quota for your user \ increased. (There may be additional costs.)" echo -e ${msg} | ${MAIL_PROG} ${user} -s "${sbj}" -c ${vs_admin}; } # Get an array of usernames who have quotas quota_users=`${QUOTASTATS} | grep "^ " | awk '{if ($3 !~ /^0K\|/) {print $1}}' | awk -F\| '{ print $1}'` for user in $quota_users; do user_quota=`${QUOTASTATS} ${user} | grep "Limit" | awk '{print $3}' | awk '{ print ($1+0)}'` user_used=`${QUOTASTATS} ${user} | grep "Current use" | awk '{print $4}' | awk '{ print ($1+0)}'` user_crit=`echo $user_quota*$crit_level | bc -l | awk -F. '{print ($1)}'` user_warn=`echo $user_quota*$warn_level | bc -l | awk -F. '{print ($1)}'` if [ $user_used -ge $user_quota ]; then level="EMERGENCY" mail_user_over $user $user_quota $user_used $level; continue fi if [ $user_used -ge $user_crit -a $user_used -lt $user_quota ]; then level="CRITICAL" mail_user_warn $user $user_quota $user_used $user_crit $level; continue fi if [ $user_used -ge $user_warn ]; then level="WARNING" mail_user_warn $user $user_quota $user_used $user_warn $level; continue fi done # Get the Virtual Server usage and quota vs_alloc=`${QUOTASTATS} | grep "Allocated/used" | awk -F\| '{print ($3+0)}'` vs_used=`${QUOTASTATS} | grep "Allocated/used" | awk -F\| '{print ($4+0)}'` vs_max=`${QUOTASTATS} | grep "Max\/available" | awk -F\| '{print ($3+0)}'` vs_crit=`echo $vs_alloc*$crit_level | bc -l | awk -F. '{print ($1)}'` vs_warn=`echo $vs_alloc*$warn_level | bc -l | awk -F. '{print ($1)}'` if [ $vs_used -ge $vs_max ]; then level="EMERGENCY" mail_vs_over $vs $vs_max $vs_used $level; exit 0 fi if [ $vs_used -ge $vs_crit -a $vs_used -lt $vs_max ]; then level="CRITICAL" mail_vs_warn $vs $vs_max $vs_used $vs_crit $level; exit 0 fi if [ $vs_used -ge $vs_warn -a $vs_used -lt $vs_crit ]; then level="WARNING" mail_vs_warn $vs $vs_max $vs_used $vs_warn $level; exit 0 fi exit 0
