Sending emails from script - empty email

1

I have some script that sending email to me from server:

#!/bin/bash
DWATYG=$(date +%d.%m.%Y -d '16 days ago')
RAPORT=$(ausearch -i -k RBS -ts $DWATYG)
echo "$RAPORT" | mutt -s "Raport RBS" my@email.com

This script launched from crontab. For every time I got empty email, without message body. If I run this commands from command line everything is ok. What's the problem?

QkiZ

Posted 2014-07-15T11:53:03.127

Reputation: 224

Try running the script from outside the directory it is located in (for example, navigate to /tmp and then call it from there with the full path). Does it run fine or generate an error? – Richard – 2014-07-15T12:20:22.113

No errors. Emails have report from ausearch tool. But if this script is runned from crontab emails are empty. – QkiZ – 2014-07-15T12:24:42.177

Answers

0

When used in a cron job ausearch needs the --input-logs option

From the man page:

--input-logs
    Use the log file location from auditd.conf as input for searching.
    This is needed if you are using ausearch from a cron job.

To get eventual error messages in your email you can redirect STDERR to STDOUT

RAPORT=$(ausearch -i -k RBS -ts $DWATYG 2>&1 )

Matteo

Posted 2014-07-15T11:53:03.127

Reputation: 6 553