System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

Not receiving email when run through cron in linux server, but receiving when run manually.How do we

 
surya_123
Occasional Visitor

Not receiving email when run through cron in linux server, but receiving when run manually.How do we


Hi All,

We are running a shell script on linux using the root user.
The functionality of the shell script is to check whether the tomcat process is running on the linux server and send an email if it is running or not running.
mailx -s "subject" emailid < /dev/null is what is being used to send email.

The emailid above is taken from environment setting file

We are receiving the email when we run the script manually but not when it is run through crontab.

Went to /etc/crontab and have initialised the EMAILTO option to our email ids..
When we check the /var/mail/root file after the cron is run, we see the message that the "Recepients emails are not specfied "

Same is the case when we schedule through normal user. Please suggest the way forward..

1 REPLY 1
Steven Schweda
Honored Contributor

Re: Not receiving email when run through cron in linux server, but receiving when run manually.How d

> mailx -s "subject" emailid < /dev/null is what is being used to send
> email.

   No, it's not.  What is the _actual_ command in the script?

> The emailid above is taken from environment setting file

   You wish.  Which "environment setting file"?  How is it read?

> Went to /etc/crontab and have initialised the EMAILTO option to our
> email ids..

   What does that mean?  As usual, showing actual actions with their
actual results (error messages, ...) can be more helpful than vague
descriptions or interpretations.  What you actually did is much more
important than what you think it all means.

   A "cron" job runs in an environment different from that of an
interactive job.  You may believe that you're setting some environment
variable somewhere, but, without seeing any of your actual code, I'd
guess that your "cron" job sees none of it.

> When we check the /var/mail/root file after the cron is run, we see
> the message that the "Recepients emails are not specfied "

   Which would be consistent with that "emailid" not really being
defined.  For a good time, throw something like "echo emailid" into your
script, and see what its value really is when the script runs.

   If there's a script-like file somewhere which defines some variable,
then you may need to read it explicitly in your "cron" script:

      .  /path/to/file