Note that there are some explanatory texts on larger screens.

plurals
  1. POCronjob missing content from mail body, manually works fine
    primarykey
    data
    text
    <p>Edit: Solution found via Barmar's answer. Added full smartctl command path and it works via crontab now.</p> <p>I have the below script:</p> <pre><code>#!/bin/bash #set -x EMAIL="admin@domain.co.uk" FILE="/root/scripts/hddreport.txt" HOST=`hostname` HDD01="/dev/sda" P=`ping -c 1 $HOST | sed '1 ! d' | awk '{print $3}'` cd /root/scripts/ echo -en "HDD health check on the server hosting" $HOST $P &gt; $FILE echo -e "\n" &gt;&gt; $FILE smartctl -H $HDD01 &gt;&gt; $FILE # The above commands do correctly write the content to $FILE (proved by removing the rm command at the bottom and doing cat on the file after) smartctl -H $HDD01 echo "\nEmailed you the health of the Hard Drive $HDD01\n" mailx -s "HDD health check complete on `date`" $EMAIL &lt; $FILE rm $FILE </code></pre> <p>which runs fine by doing bash /root/scripts/diskhealth.sh as it shows this in my mailbox:</p> <pre><code>HDD health check on the server hosting domain.co.uk (0.0.0.0) smartctl 5.40 2010-07-12 r3124 [x86_64-unknown-linux-gnu] (local build) Copyright (C) 2002-10 by Bruce Allen, http://smartmontools.sourceforge.net SMART Health Status: OK </code></pre> <p>But when I let it run via crontab using any of the following syntax:</p> <pre><code>X 20 * * * /bin/bash /root/scripts/diskhealth.sh X 20 * * * /bin/sh /root/scripts/diskhealth.sh X 20 * * * /root/scripts/diskhealth.sh </code></pre> <p>it puts everything but the smartctl disk check:</p> <pre><code>HDD health check on the server hosting domain.co.uk (0.0.0.0) </code></pre> <p>Here's what it shows if I add extra echo lines:</p> <pre><code>This is a test HDD health check on the server hosting domain.co.uk (0.0.0.0) </code></pre> <p>Amended script for "This is a test" below:</p> <pre><code>#!/bin/bash #set -x EMAIL="admin@domain.co.uk" FILE="/root/scripts/hddreport.txt" HOST=`hostname` HDD01="/dev/sda" P=`ping -c 1 $HOST | sed '1 ! d' | awk '{print $3}'` cd /root/scripts/ echo "This is a test" &gt; $FILE echo -en "HDD health check on the server hosting" $HOST $P &gt;&gt; $FILE echo -e "\n" &gt;&gt; $FILE smartctl -H $HDD01 &gt;&gt; $FILE smartctl -H $HDD01 echo "\nEmailed you the health of the Hard Drive $HDD01\n" mailx -s "HDD health check complete on `date`" $EMAIL &lt; $FILE rm $FILE </code></pre> <p>Here is the /var/log/syslog output from cron:</p> <pre><code>Jun 6 20:25:01 hostname /USR/SBIN/CRON[1018112]: (root) CMD (bash /root/scripts/diskhealth.sh) Jun 6 20:25:01 hostname postfix/pickup[1016576]: 5740356613F: uid=0 from=&lt;root&gt; Jun 6 20:25:01 hostname postfix/cleanup[1018125]: 5740356613F: message-id=&lt;20130606192501.5740356613F@hostname&gt; Jun 6 20:25:01 hostname postfix/qmgr[292015]: 5740356613F: from=&lt;root@hostname&gt;, size=465, nrcpt=1 (queue active) Jun 6 20:25:01 hostname postfix/pickup[1016576]: 631F156613E: uid=0 from=&lt;root&gt; Jun 6 20:25:01 hostname postfix/cleanup[1018125]: 631F156613E: message-id=&lt;20130606192501.631F156613E@hostname&gt; Jun 6 20:25:01 hostname postfix/qmgr[292015]: 631F156613E: from=&lt;root@hostname&gt;, size=759, nrcpt=1 (queue active) Jun 6 20:25:01 hostname pvemailforward[1018132]: forward mail to &lt;root@localhost.localdomain&gt; Jun 6 20:25:01 hostname postfix/pickup[1016576]: B597B566148: uid=65534 from=&lt;nobody&gt; Jun 6 20:25:01 hostname postfix/cleanup[1018125]: B597B566148: message-id=&lt;20130606192501.631F156613E@hostname&gt; Jun 6 20:25:01 hostname postfix/local[1018131]: 631F156613E: to=&lt;root@hostname&gt;, orig_to=&lt;root&gt;, relay=local, delay=0.39, delays=0.16/0/0/0.23, dsn=2.0.0, status=sent (delivered to command: /usr/bin/pvemailforward) Jun 6 20:25:01 hostname postfix/qmgr[292015]: 631F156613E: removed Jun 6 20:25:01 hostname postfix/qmgr[292015]: B597B566148: from=&lt;nobody@hostname&gt;, size=963, nrcpt=1 (queue active) Jun 6 20:25:01 hostname postfix/smtp[1018135]: B597B566148: to=&lt;root@localhost.localdomain&gt;, relay=none, delay=0.16, delays=0.12/0/0.04/0, dsn=5.4.4, status=bounced (Host or domain name not found. Name service error for name=localhost.localdomain type=A: Host not found) Jun 6 20:25:01 hostname postfix/qmgr[292015]: B597B566148: removed Jun 6 20:25:01 hostname postfix/cleanup[1018125]: D6570566147: message-id=&lt;20130606192501.D6570566147@hostname&gt; Jun 6 20:25:01 hostname postfix/smtp[1018130]: 5740356613F: to=&lt;admin@domain.co.uk&gt;, relay=ASPMX.L.GOOGLE.COM[173.194.67.27]:25, delay=0.68, delays=0.12/0/0.19/0.36, dsn=2.0.0, status=sent (250 2.0.0 OK 1370546701 iy4si8635735wic.1 - gsmtp) Jun 6 20:25:01 ds9453 postfix/qmgr[292015]: 5740356613F: removed </code></pre> <p><strong>The email is received, just missing the smartctl output.</strong></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