crontab fails to run script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting crontab fails to run script
# 1  
Old 11-23-2009
crontab fails to run script

OS is Ubuntu 8.04.3. When I run the command:

Code:
/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
Code:
#!/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
Code:
# m h  dom mon dow   command
0-59/5 * * *   *     /usr/bin/syslogMailer < /etc/syslog.pipes/criticalMessages > /dev/null 2>&1

# 2  
Old 11-23-2009
your syslog should say why it is not running...

check it, if not able to find, paste the CRON part here.
# 3  
Old 11-24-2009
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.

Code:
cat /tmp/test
test1
test2

the crontab now looks like this:

Code:
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?
# 4  
Old 11-25-2009
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.
# 5  
Old 11-25-2009
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace string works on command-line but fails when run from shell script

I wish to replace "\\n" with a single white space. The below does the job on command-line: $ echo '/fin/app/scripts\\n/fin/app/01/sql' | sed -e 's#\\\\n# #g'; /fin/app/scripts /fin/app/01/sql However, when i have the same code to a shell script it is not able to get me the same output:... (8 Replies)
Discussion started by: mohtashims
8 Replies

2. Shell Programming and Scripting

Bash script fails when run as file

The following bash script fails with error message: "./phpquery_KNBB_html_reader.sh: line 65: syntax error near unexpected token `done'" when do ./<scriptname> in the shell. However when I copy-paste the entire contents of the file directly into a shell environment it runs ok returning the intended... (2 Replies)
Discussion started by: BurritoSolution
2 Replies

3. Shell Programming and Scripting

Script fails to run properly when run from CRONTAB

Hello all, I'm trying to write a script to gather and send data and it works just fine at the bash command line, but when executing from CRON, it does not run properly. My scripting skills are pretty limited and there's probably a better way, but as I said it works at the command line, but... (12 Replies)
Discussion started by: rusman
12 Replies

4. Shell Programming and Scripting

Script won't fails when running from crontab

Hi, My script runs fine from the command line, but when crontab tries to launch it encounters lack of permissions: could not open /dev/kbd to get keyboard type US keyboard assumed could not get keyboard type US keyboard assumed split: Permission denied This is the head of the script: ... (2 Replies)
Discussion started by: Cvg
2 Replies

5. Shell Programming and Scripting

Script fails with ORA-20000 when run with su

Hi, I have a ksh script that runs as root ans issues several commands as a user differente from root as 'su <user> -c "command" ' . It works fine except for one step where the command executes sql statements. That command fails with ORA-20000. Now the strangest thing, if I place a read command... (5 Replies)
Discussion started by: naf
5 Replies

6. Shell Programming and Scripting

run script through crontab using ksh

hi i have a script called test.sh. the content is ls >> crontest.txt. if i run manually it's giving output.but if i scheduled in crontab it's not giving output. crontab entry: 02 * * * * /sms5/SMSHOME/eds_sh/test.sh >> /sms5/SMSHOME/eds_sh/testfile/logfile 2>&1 I am using ksh.is there... (2 Replies)
Discussion started by: muraliinfy04
2 Replies

7. Shell Programming and Scripting

run script 1 minute interval without CronTab

I am using Solaris 9. I wish to run my script every 1 minute inteval. Though i can run it using below entry in crontab. * * * * /export/home/username/script/file_exist_&_run.sh in short above script will check whether a specific file exist in a directory. If it found it will inovke another... (10 Replies)
Discussion started by: thepurple
10 Replies

8. Shell Programming and Scripting

How do i run a shell script without crontab.

Hi Folks, Could you please suggest me how to run a shell script on a solaris env without using crontab. I am actually trying to write a shell script which will grep "WORD" in the logfile andd sends a email.Thanks in advance. Thanks Sandeep. (3 Replies)
Discussion started by: sandeep anand
3 Replies

9. Shell Programming and Scripting

Running script that sends an html formatted email fails when its run as cronjob

Hi Im very new at working with unix and this problem I simply can not understand. I know there are a lot of threads about problems with shell scripts behaving differently when run from a terminal and from a cronjob. I have tried everything(almost) but I still havent cracked this problem. Im... (15 Replies)
Discussion started by: Nightowl
15 Replies

10. Shell Programming and Scripting

recurring run of sh script in crontab

Hello gurus. I have a problem: my crontab -e is looks like this: ORACLE_SID=bla-bla * 21 * * * (sqlplus hotback/hotback @/oracle/backups/bla-bla/scripts/hotback/daily_hotback.sql) 0 19 * * * /oracle/backups/dev10g/scripts/exports/daily_exports.sh 0 1 * * *... (4 Replies)
Discussion started by: MarGur
4 Replies
Login or Register to Ask a Question