Note that there are some explanatory texts on larger screens.

plurals
  1. POPipe cronjob errors to mail
    primarykey
    data
    text
    <p>I have a job for root</p> <pre><code>0 0 * * * /usr/bin/time /path/to/mysqlbackup.sh | /bin/mail -s "MySQL Backup" "admin@example.com" </code></pre> <p>And the script will echo out some information when it is run, which is then emailed as expected.</p> <p>The problem is if an error occurs, it is not being sent to the email, so I'm not able to catch it. If I view the <code>mail</code> of the root user I see errors like</p> <blockquote> <p>mysqldump: Got error: 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) when trying to connect</p> </blockquote> <p>How can I make all output caused from the script be sent to my email?</p> <hr> <h3>Notes</h3> <p>Cron job</p> <pre><code>* * * * * (/usr/bin/time /root/utils/test.sh 2&amp;&gt;1) | /usr/bin/tee /tmp/cron.test | /bin/mail -s "test" "srobbins@example.com" </code></pre> <p>Message found in root's mail</p> <pre><code>[root@example utils]# mail Mail version 8.1 6/6/93. Type ? for help. "/var/spool/mail/root": 1 message 1 new &gt;N 1 root@example Fri Oct 11 08:35 23/1025 "Cron &lt;root@example&gt; (/usr/bin/time /root/utils/test.sh 2&amp;&gt;1) | /usr/bin/tee /tmp/cron.test | /bin/mail -s "test" "srobbins@example.com"" &amp; Message 1: From root@example.com Fri Oct 11 08:35:01 2013 Date: Fri, 11 Oct 2013 08:35:01 -0700 From: root@example.com (Cron Daemon) To: root@example.com Subject: Cron &lt;root@example&gt; (/usr/bin/time /root/utils/test.sh 2&amp;&gt;1) | /usr/bin/tee /tmp/cron.test | /bin/mail -s "test" "srobbins@example.com" Content-Type: text/plain; charset=UTF-8 Auto-Submitted: auto-generated X-Cron-Env: &lt;SHELL=/bin/sh&gt; X-Cron-Env: &lt;HOME=/root&gt; X-Cron-Env: &lt;PATH=/usr/bin:/bin&gt; X-Cron-Env: &lt;LOGNAME=root&gt; X-Cron-Env: &lt;USER=root&gt; Null message body; hope that's ok </code></pre> <p>Contents of <code>/root/utils/test.sh</code></p> <pre><code>echo "Starting backup at $(date)" mysql -u potato -e "show status" # produces error FILE="/path/to/file.bak" FILESIZE=`du -h $FILE | cut -f1` echo $FILESIZE </code></pre> <p>/tmp/cron.test is empty</p> <p>The body of the dispatched email is empty</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload