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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Error in cron job; shruthinagaraj UNIX for Dummies Questions & Answers 1 10-28-2008 10:27 AM
cron entry error capeme Shell Programming and Scripting 6 10-26-2006 10:05 AM
cron error capeme UNIX for Dummies Questions & Answers 4 10-25-2006 04:07 PM
mmap error - only when from cron?!?!? Bicks Filesystems, Disks and Memory 1 08-01-2006 02:12 PM
Script/cron error Bab00shka UNIX for Dummies Questions & Answers 1 06-12-2002 07:41 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-28-2008
shruthinagaraj shruthinagaraj is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 3
Question Error in cron job;

Hi All,

please help me out with this problem.

While running my mail_out_original.ksh in CRT window, it disconnects from the server saying not connected

Here is my code : (please see the attachment)
____________________________________________________________

#!/bin/ksh

## Load .profile to make sure crontab run jobs are loading all env variables
. $HOME/.profile

## Change into the directory
cd /u/gcsm_admin/mail_out

## Create the touch file
touchfile="/u/gcsm_admin/mail_out/running"

## If there is no other mail_out running the remove the touchfile
NOTRUN=$(ps -ef | grep "mail_out.ksh" | wc -l)
if [ $NOTRUN -le 2 ]
then
rm $touchfile 2>/dev/null
fi

## Exit routine
fnExit()
{
if [ -r $touchfile ]
then
rm $touchfile 2>/dev/null
fi
exit -1
}

## Set a trap to remove the touch file
trap fnExit ERR

## If we are already running then exit
if [ -r $touchfile ]
then
exit
fi

## Create a touch file
touch $touchfile

## Extra process to restart if something hangs
(
PARENT=$$
sleep 600
RUNNING=$(ps -ef | egrep "$PARENT.*mail_out" | wc -l)
if [ $RUNNING -gt 1 ]
then

echo "The pop email processor has been restarted.

Please verify this process actually worked by checking if email from case updates are being sent.

Thanks,

Support" | mailx -s 'MAIL OUT PROGRAM DOWN!' nagarajec@gmail.com
rm $touchfile
/usr/local/bin/killpg $$
exit -1
fi
)&
WAITPROC=$!

cnt=0

while [ $cnt -lt 1 ]
do

## Increment our counter
cnt=$(expr $cnt + 1)

## Run the program
/u/gcsm_admin/mail_out/mail_out.pl
sleep 1
done

## Get rid of the touch file
rm $touchfile

## Kill the monitor process and exit
trap "" ERR
/usr/proc/bin/ptree $WAITPROC | awk '{ print "kill -9 " $1 " 2> /dev/null "}' | ksh
exit 0


____________________________________________________________


your help will be appreciated ...
  #2 (permalink)  
Old 10-28-2008
methyl methyl is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 1,184
I suspect that one of your kills is killing the login shell as well as the intended program.

This section of script may be the problem

rm $touchfile
/usr/local/bin/killpg $$
exit -1

I depends what "killpg" actually does. It is not a standard unix command.


Or possibly this area of script which ruthlessly kills parents and children of $WAITPROC.
/usr/proc/bin/ptree $WAITPROC | awk '{ print "kill -9 " $1 " 2> /dev/null "}' | ksh
BTW. Use "kill -9" at your peril. It is a last resort and not a way to end things tidily.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:22 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0