1

I have a crontab task running every 5 minutes. It writes an output (result of the .sh file run by the crontab) to the /var/spool/mail/user. Should I be worried that this spooler will build up and slow down the system over time? Do these entries ever get cleared out? Are they only temporary? If possible, can I disable it.

  • This is a question about what it takes to program safely on Unix. It is on topic for SO. – Jonathan Leffler Jan 3 '12 at 20:41
  • I hope the output written by the crontab task is formatted as a valid e-mail message. If it isn't, you're messing up the user's e-mail inbox. – Keith Thompson Jan 3 '12 at 21:16
4

The messages stay there until the user whose mail it is reads and deletes the mail. That might be years later (I kid you not!).

  • No, the directory is not cleared out by anything.
  • Yes, you need to be worried about the problem of filling up your disk with unread email.
  • 2
    A possible solution might be to forward your mail to some email address that you really are reading. Another would be to redirect in your crontab the stdout & stderr outputs. If they are redirected or empty, crond won't send any email. – Basile Starynkevitch Jan 3 '12 at 20:50
  • To send the email to another email address in your crontab edit it and add a line similar to this: MAILTO=user@example.com – kaptk2 Jan 3 '12 at 22:29
1

The contents of the /var/spool/mail/user directory remain until the user deletes the mail. You may wish to install a script that runs via cron to remove files older than a certain date, and tweak this as you monitor your system.

  • 2
    Don't do this without notifying your users well in advance. I would consider an automated script that deletes my e-mail to be hostile. – Keith Thompson Jan 3 '12 at 21:17
-2

I added this line to crontab to my user root:

* */2 * * * /bin/su - root -c cat/dev/null > /var/spool/mail/root

So every 2 hours, it is cleaned for that specific user (root).

  • 1
    That schedule doesn't do what you think it does, and there's no need to su to root if you're already running as root. – womble Mar 16 '17 at 1:01

Your Answer

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