Null message body; hope that's ok

16,384

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.

Share:
16,384

Related videos on Youtube

Sandip
Author by

Sandip

Updated on September 18, 2022

Comments

  • Sandip
    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
      Ludwig Schulze over 9 years
      what is the content of the cleanSDP2xLogs.sh script?
    • Sandip
      Sandip over 9 years
      LOGDIR=/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
      Alen Milakovic over 9 years
      @Sandip Put that information in the body of the question, not in a comment.
  • dhag
    dhag over 6 years
    That seems to be what the existing answer from over three years ago points to.
  • Kusalananda
    Kusalananda about 5 years
    How 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)?