The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
error in running shell script in cron sari Shell Programming and Scripting 3 04-16-2008 01:09 AM
Email sending through a shell script memonks UNIX for Dummies Questions & Answers 3 11-11-2007 09:21 PM
Sending attachments using email through shell script symhonian Shell Programming and Scripting 6 01-27-2006 06:41 AM
sending email from KSH unix script. rosh0623 Shell Programming and Scripting 3 07-26-2005 12:36 AM
Cron running shell scripts. cfoxwell UNIX for Dummies Questions & Answers 3 09-26-2001 08:35 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-23-2008
Registered User
 

Join Date: Jul 2008
Posts: 8
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!!)

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!!
Reply With Quote
Forum Sponsor
  #2  
Old 07-23-2008
Moderator
 

Join Date: Sep 2007
Location: Germany
Posts: 1,022
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.
Reply With Quote
  #3  
Old 07-23-2008
Registered User
 

Join Date: Jul 2008
Posts: 8
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
Reply With Quote
  #4  
Old 07-23-2008
Registered User
 

Join Date: Oct 2007
Posts: 1
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.
Reply With Quote
  #5  
Old 07-23-2008
Registered User
 

Join Date: Jul 2008
Posts: 8
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
Reply With Quote
  #6  
Old 07-23-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
The FAQ section has an extensive posting about troubleshooting cron jobs. cron and crontab
Reply With Quote
  #7  
Old 07-23-2008
Registered User
 

Join Date: Feb 2008
Posts: 49
Give full permision

Try to give full permission for that file

or

chmod 755 finename
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 03:31 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0