OS is Ubuntu 8.04.3. When I run the command:
/usr/bin/syslogMailer < /etc/syslog.pipes/criticalMessages
From a bash shell it works and i receive an email as per the script however when run from crontab it does not work. Can anyone explain why and how to fix it?
/usr/bin/syslogMailer
#!/bin/bash
# syslogMailer: a script to read stdin and turn each line into an alert
# email typically this is used to read a named-pipe written to by syslog
#
# example usage: syslogMailer < /etc/syslog.pipes/criticalMessages
#
alertRecipient="alerts@example.com" # the mail recipient for alerts
sender="admininstrator@example.net" # the mail sender
TMOUT=1 # don't wait > 1 second for input
# process each line of input and produce an alert email
cat <<EOF | sendmail -t -oi
To: ${alertRecipient}
Reply-to: ${sender}
From: ${sender}
Subject: "critical error on syslog"
$(while read line
do
# remove any repeated messages
echo ${line} | grep "message repeated" > /dev/null 2>&1
if test $? -eq 1
then
# output the alerts
echo "${line}"
fi
done)
EOF
crontab -e
# m h dom mon dow command
0-59/5 * * * * /usr/bin/syslogMailer < /etc/syslog.pipes/criticalMessages > /dev/null 2>&1