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 LefflerJan 3, 2012 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 ThompsonJan 3, 2012 at 21:16
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.
2A possible solution might be to forward your mail to some email address that you really are reading. Another would be to redirect in your
crontabthe stdout & stderr outputs. If they are redirected or empty,
crondwon't send any email.– Basile StarynkevitchJan 3, 2012 at 20:50
To send the email to another email address in your crontab edit it and add a line similar to this: MAILTOemail@example.com– kaptk2Jan 3, 2012 at 22:29
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.
2Don't do this without notifying your users well in advance. I would consider an automated script that deletes my e-mail to be hostile. Jan 3, 2012 at 21:17
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).
1That schedule doesn't do what you think it does, and there's no need to
rootif you're already running as
root.– womble ♦Mar 16, 2017 at 1:01