Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»General Articles»How to disable crontab output and emails in Linux

    How to disable crontab output and emails in Linux

    By RahulFebruary 25, 20233 Mins Read

    Question: How can I disable email alerts from cron jobs? How can I disable wget to create a new file each time? Why I am receiving too many e-mails to my root account from crontab?

    Advertisement

    When running cron jobs on Linux, it’s common to receive output from the job in the form of email notifications or log files. However, in some cases, you may not want to receive output at all, especially if the job is running frequently or generates a lot of output. In this article, we’ll show you how to disable crontab output on Linux.

    Method 1: Redirect output to /dev/null

    The easiest way to disable crontab output is to redirect the output to /dev/null. Which is a special file that discards all data written to it. By redirecting output to /dev/null, you can effectively discard all output generated by the cron job.

    To redirect output to /dev/null, add the following line to your crontab entry:

    1
    *   *   *   *   *   command  >  /dev/null 2>&1

    This will redirect both standard output and standard error to /dev/null, effectively disabling all output from the command.

    This is more useful for the cron jobs running wget command. I have a cron job with wget run every minute. Which creates a new file each time wget runs with crontab under the home directory. So I configured it as below and now my home is clean.

    1
    0  2 * * * wget -q -O /dev/null  http://example.com/cron.php

    Method 2: Set the MAILTO environment variable

    By default, cron sends email notifications for each job. However, you can disable email notifications by setting the MAILTO environment variable to an empty value.

    To disable email notifications for a specific job, add the following line to your crontab entry:

    1
    MAILTO=""

    This will set the MAILTO environment variable to an empty value, disabling email notifications for the current job.

    Method 3: Modify the cron daemon configuration

    If you want to disable crontab output for all jobs on your system, you can modify the cron daemon configuration. By default, the cron daemon sends email notifications for all jobs, but you can modify the configuration to disable email notifications.

    To modify the configuration, edit the “/etc/crontab” file and add the following line:

    1
    MAILTO=""

    This will set the default MAILTO value to an empty value, disabling email notifications for all jobs.

    Conclusion

    By using the methods outlined in this article, you can easily disable crontab output on Linux. Whether you choose to redirect output to /dev/null, set the MAILTO environment variable, or modify the cron daemon configuration, it’s important to test your changes thoroughly to ensure that your cron jobs are running correctly. With these techniques, you can have greater control over the output and notifications you receive from cron jobs on your Linux system.

    cron crontab logs notification
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Configure Postfix to Use Gmail SMTP on Ubuntu & Debian

    Deploying Flask Application on Ubuntu (Apache+WSGI)

    OpenSSL: Working with SSL Certificates, Private Keys and CSRs

    View 4 Comments

    4 Comments

    1. xuwjad on March 10, 2021 2:11 am

      doesnt work i keep seeing this in syslog every minute: “wget http://example.com/cron.php >/dev/null 2>&1″

      Reply
    2. Arnab on October 25, 2020 5:32 am

      Why is >/dev/null 2>&1 appended to the line after MAIL TO=”[email protected]” ?

      Reply
    3. Dave on March 27, 2019 8:58 am

      Thanks! I had over 150.000 files in my home directory from a cronjob running wget every two minutes.

      Reply
    4. Jamey on August 1, 2018 3:51 am

      Thank you Mr. Rahul. It’s very helpful

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Configure Postfix to Use Gmail SMTP on Ubuntu & Debian
    • PHP Arrays: A Beginner’s Guide
    • Deploying Flask Application on Ubuntu (Apache+WSGI)
    • OpenSSL: Working with SSL Certificates, Private Keys and CSRs
    • How to Create and Read List in Python
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.