I need some help to improve the idea/implementation.Scenario is local mini ISP. users accounts are stored in freeradius/mysql. The task is to send user email who have consumed 80% of there assigned quota.

I have configured bash script scheduled run after every 1 hour, that checks for users in mysql table who have downloaded 75% of quota assigned to them and then ADD there username and email to a file /tmp/overquotauser.txt like this

user1 user1email@domain.com
user2 user2email@domain.com
user3 user3email@domain.com

When user account gets renewed, his name gets removed from the /tmp/overquotauser.txt

Now what I want is to send email to these users, its easy but what I want is to prevent repeated email to user every hour. Example is if a user have consumed 80%, then only one email should send to user, and not every hour. any idea how this can be done?

  • Since you are storing username and email both in the text file - you can remove the email column once the email has been sent (but keep the username in the file). In the next invocation of the cron job, send email only to the users who have emailids mentioned. – amisax Aug 3 '15 at 5:45
  • can u give some examples plz? – Syed Jahanzaib Aug 3 '15 at 7:57
  • @AmitKumar quota check is not for local disk. its for internet users whose data is stored in mysql table. I can check the Quota percentage of each use with the help of script, but issue is how to send email without repeating as described in the query. I have updated the query. – Syed Jahanzaib Aug 3 '15 at 15:04

You can use a mysql table for this,since you are already working in mysql ! A table like this should suffice -

create table (
    userid varchar(100),
    useremail varchar(100),
    int mailsent default 0

Your creator job will create (or delete) rows from this table. Your mailer will pull all rows with mailsent set as 0, send mail, and set mailsent as 1.

However, if you really, really, really want to use the text file - here is an approach -

  1. Let's say your creator cron job's first invocation creates a file like this -

  2. Now at some time your mailer task runs , it will select the lines from this file that have emailid , mail the recipients and remove the email ids in those lines. ( You can use perl or sed for this - be careful of synchronous writing of this file from creator) after this operation your file will become

  3. After a while your creator adds two more users user4 and user5. Your file now becomes

  4. When the mailer task runs again, it will email only to people who have email ids specified 0 as in step 2.

There are multiple ways for this schema to work.

  • Thank you, Finally I managed to sort it :) I create extra colum with name of qmail with value of 0 and 1 and the script modify it accordingly and mailer checks for this flag :) thank you – Syed Jahanzaib Aug 4 '15 at 8:47

You can use any one of following two approaches.

I) Every one hour create a file /tmp/overquotausernew.txt and compare this file with old file /tmp/overquotausernew.txt. If any new users are found in newly created file, then send email to only those users and merge newly created file with /tmp/overquotauser.txt

In this way, you will maintain only one file with all usernames to which email is sent. And script will chk for any new users to which mail is not sent.

II) You can create a script to send mail such that it will check if mail to particular user from /tmp/overquotauser.txt is sent or not within last 24 hrs. If mail is sent in last 24 hrs then script will do nothing else it will send mail to that user.


One way could be to use built-in quota tools of *nix systems... as from here.

If Soft Limit is 800MB and Hard Limit is 1000MB then user will be emailed when Soft Limit is reached, allowing user to still create files until Hard Limit is reached.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.