Running a shell script in cron...email not sending - help??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running a shell script in cron...email not sending - help??
# 1  
Old 07-23-2008
Running a shell script in cron...email not sending - help??

I am pretty new to Unix shell scripting, but wondered if anyone could help (in layman's terms if possible!!) Smilie

I have a shell script which ultimately sends an alert to an email address if part of a batch of programs fails. Here's the script that sends the email:

Script: 6check.csh
#!/bin/csh
set alertperson = `cat /export/home/bdodym/alert.person`
if (-f critabend.tag ) then
cat callout6.msg | rmail $alertperson
rm critabend.tag
endif

This is where $alertperson will be forename.surname@address.com designation in the alert.person script

From the command line, all runs fine.

However, if I run through cron, it still seems to be executing the scripts (e.g files are created that I'm asking the script to do generally), but the email is not being sent as I would hope. In the below crontab, 6start.sh has a number of scripts to run through, the last of which is 6check2.csh (as per above)

crontab -l
#!/bin/csh
#############################################
# Minute Hour Month Day Month Weekday Command
# ___________________________________________________________
# 0 01 * * * Job_1
#
51 * * * * /export/home/bdodym/6start.sh

Does anyone know if there is anything additional I need to do add to either the script, or cron, to ensure the email sends? I think (from my VERY limited knowledge of this kind of thing!) that its something to do with the fact cron is running in the background rather than the terminal, as per the command line success. But, this is the final piece of the jigsaw and I just need to ensure I can get it to fit!! Smilie
# 2  
Old 07-23-2008
Have the output of that cronjob redirected to some file like
Code:
51 * * * * /export/home/bdodym/6start.sh >> /somelogdir/6start.sh.out 2>&1

and check what's wrong. Additionally you can add a "set -x" into your shell script to see what's going on inside.
Don't forget that cronjobs usually don't have the same environment like when a user would start the script - so you should source the .profile or .kshrc or .bashrc, whatever your environment setup files are.
# 3  
Old 07-23-2008
zaxxon - thankyou for your reply. I was just reading up about "source". So if I were to source it, would I just add the source to 6check.sh (the emailing bit) or 6start.sh too (which, as mentioned just contains a list of scripts to run, as per below...)

#!/bin/sh

6jobstatus.sh
6clean.sh
6check.sh
6check2.csh

Thanks,
Tim
# 4  
Old 07-23-2008
use vi editor to create a file using .sh extension which will have shell scripts to execute.
then execute this file using command
sh filename.sh
e.g. if u have created a shell file sample.sh then u will execute this file using

sh sample.sh

this command...
go and try different kinds of shell scripts you will definitely explore more about UNIX.
# 5  
Old 07-23-2008
Hi sumitbabar

I already have the .sh extensions, my problem is my emails aren't sending when run from cron. All is fine from the command line.
Thanks, Tim
# 6  
Old 07-23-2008
The FAQ section has an extensive posting about troubleshooting cron jobs. https://www.unix.com/answers-frequent...n-crontab.html
# 7  
Old 07-23-2008
Give full permision

Try to give full permission for that file

or

chmod 755 finename
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Troubles running DB2 command in shell script via cron

Hi there, Now I'm facing error regarding running shell script via cron. The shell script which is required to get value from database. Below is the main part of shell script. #/bin/bash #connect to database(1) db2 connect to $database user xxxx using yyyy #set values from... (3 Replies)
Discussion started by: Rohan Kishibe
3 Replies

2. Shell Programming and Scripting

Sending email in shell script

Can anyone help me out how to send the email without the word success while sending to the recipient. echo "success" | mailx -s "webshell instance has been started noiw" implementation@tkcl.com (8 Replies)
Discussion started by: ramkumar15
8 Replies

3. Shell Programming and Scripting

Running shell script via cron

Hi Guys, I do have a shell script that I scheduled to run via the cron but when the script don't run. But when I run the script manually it does run perfectly... What might be the problem? Thanks. (1 Reply)
Discussion started by: Phuti
1 Replies

4. Shell Programming and Scripting

Running Shell Script in the cron, background process

Hi, i was looking for an answer for some trouble im having runing a script in the cron, thing is, that when i run it manually it works just fine. But when cron runs it, it just doenst work. I saw a reply on a similar subject, suggesting that the . .profile worked for you, but im kind of... (9 Replies)
Discussion started by: blacksteel1988
9 Replies

5. Shell Programming and Scripting

Running Shell Script in the cron, background proccess

Hi, i was looking for an answer for some trouble im having runing a script in the cron, thing is, that when i run it manually it works just fine. But when cron runs it, it just doenst work. I saw a reply on a similar subject, suggesting that the . .profile worked for you, but im kind of... (0 Replies)
Discussion started by: blacksteel1988
0 Replies

6. Shell Programming and Scripting

Sending email from shell script

Hi, I need to send email from a shell script. i echoed some information to a file and i am doing cat command in the email syntax thanks (2 Replies)
Discussion started by: rocky1954
2 Replies

7. Shell Programming and Scripting

Shell script for sending automatic email to personal mail id

hi guys, I need a shell script to send mail automatically to my personal mail id like xxxx@hotmail.com but while experimenting with "mail" command I faced following problems. cat text1.txt | mail -s 'test mail' xxxx@hotmail.com command successfully executed but while checking for... (4 Replies)
Discussion started by: rrd1986
4 Replies

8. Shell Programming and Scripting

error in running shell script in cron

#!/bin/bash CLASSPATH=. #CLASSPATH=${CLASSPATH}:${INSTALL_PATH}home/squidlog/CopyFile.java CLASSPATH=${CLASSPATH}:${INSTALL_PATH}usr/java/latest/lib/*.jar javac CopyFile.java echo "CLASSPATH=$CLASSPATH" #home/wbiadmin/JRE1.4.2/j2re1.4.2_15/bin/java CopyFile /usr/bin/java... (3 Replies)
Discussion started by: sari
3 Replies

9. UNIX for Dummies Questions & Answers

Email sending through a shell script

Hi everyone, I have a shell script that I use to send some emails with attachments. Based on the attachment file that is being sent, I choose the recipient. My file_list.txt looks like this CAJ.txt;sm@email.com KXLD.txt;jc@email.com I do a grep on this file to look for the file name and... (3 Replies)
Discussion started by: memonks
3 Replies

10. Shell Programming and Scripting

Sending attachments using email through shell script

Hi all, I have written a shell script which sends emails with attachments to our clients. All our attachments are simple flat files (.txt format). The script is working fine and sending the attachments to the mail-ids except that, when i am sending the attachments to non-outlook users (Like... (6 Replies)
Discussion started by: symhonian
6 Replies
Login or Register to Ask a Question