crontab fails to run script

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

your syslog should say why it is not running...

check it, if not able to find, paste the CRON part here.

I have changed the file that it reads from to ensure their is something in it whilst testing and set it to run every minute.

cat /tmp/test
test1
test2

the crontab now looks like this:

0-59/1 * * *   *     /usr/bin/syslogMailer < /tmp/test > /dev/null 2>&1

the output in syslog is:

Nov 24 15:55:01 ggnas01 /USR/SBIN/CRON[8672]: (root) CMD (/usr/bin/syslogMailer < /tmp/test > /dev/null 2>&1)
Nov 24 15:56:01 ggnas01 /USR/SBIN/CRON[8684]: (root) CMD (/usr/bin/syslogMailer < /tmp/test > /dev/null 2>&1)

Not sure if this helps at all?

I am guessing that having the while loop inside the cat EOF command is somehow interpreted by cron differently?

Ok it turns out that I had to put the full path to sendmail "/usr/sbin/sendmail".

I did not realise cron did not have the same paths as root.

If you need PATH for all your crons.. Just add a variable PATH to crontab .

Some of environment variables: so that you dont need to have complete path etc etc in each script
HOME=user's-home-directory
LOGNAME=user's-login-id
PATH=/usr/bin:/usr/sbin:.
SHELL=/usr/bin/sh