Null message body; hope that's ok
You need to either replace the |
with &&
or let the script output the data to stdout and use |
.
When using &&
, the mail
command would only be run when the script exits with 0.
When using the pipe character, your script needs to send the data to stdout so the pipe can pass it on to mail
.
In what you wrote, the script writes data to the file and mail
reads from the file in parallel — and mail
ends up reading the file before the script has written anything to it.
Related videos on Youtube
Sandip
Updated on September 18, 2022Comments
-
Sandip over 1 year
I have the following command below as part of a cronjob. When I run the command via cron or at the command line, I get
Null message body; hope that's ok
.The contents of the email are empty but when I check the
/tmp/sdplogs.out
file it has content in it.The script
/dproxy/scripts/cleanSDP2xLogs.sh
sends output to the file/tmp/sdplogs.out
.What am I doing wrong? Any help would be greatly appreciated.
$ /dproxy/scripts/cleanSDP2xLogs.sh | mail -s 'SDP2.X Prod LogArchiving Report' [email protected] < /tmp/sdplogs.out Null message body; hope that's ok
-
Ludwig Schulze over 9 yearswhat is the content of the cleanSDP2xLogs.sh script?
-
Sandip over 9 yearsLOGDIR=/dproxy/logs/was8 find $LOGDIR/scs -name 'app.log' -mtime +30 | xargs rm -v > /tmp/sdplogs.out 2>&1 find $LOGDIR/sas -name 'app.log' -mtime +30 | xargs rm -v >> /tmp/sdplogs.out 2>&1 find $LOGDIR/scs -name 'app.log' -mtime +7 | xargs gzip -v >> /tmp/sdplogs.out 2>&1 find $LOGDIR/sas -name 'app.log' -mtime +7 | xargs gzip -v >> /tmp/sdplogs.out 2>&1
-
Alen Milakovic over 9 years@Sandip Put that information in the body of the question, not in a comment.
-
-
dhag over 6 yearsThat seems to be what the existing answer from over three years ago points to.
-
Kusalananda about 5 yearsHow do you that the user's
mail
has an-a
option? What does the<< ""
do at the end (it looks like the start of a here-document), did you mean<<<""
(a here-string)?