Error in cron job;


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error in cron job;
# 1  
Old 10-28-2008
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  
Old 10-28-2008
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cron job - Need to run Cron every quarter at particular time

Hi, 1) If some job supposed to run on 1st of every month at 7 AM In cron job when we have a blackout on the 1st ( i.e when 1st falls on a sunday ) how can we make the job run the next business day? 2) How can we run a job on 25th of every quarter 7 AM(jan,apr,jul,oct) And if 25th... (5 Replies)
Discussion started by: System Admin 77
5 Replies

2. UNIX for Dummies Questions & Answers

Error while running a script through cron job

Hi Team, When i am running the below query manually it is giving me the right output i.e. export PATH=/usr/sbin:/usr/bin:/sbin:/bin:$PATH ADMIN=abc@abc.com CPU_HIGH=`sar|awk '{print $9}'|sort -n|head -5|sed -n 5p` CPU_MAX=`echo "scale=3; 100-$CPU_HIGH" | bc` CPU_LOW=`sar|awk '{print... (13 Replies)
Discussion started by: Ekamjot
13 Replies

3. Shell Programming and Scripting

Commented cron job -- cron monitoring

Hi I have a requirement to write a shell script,that will check the all commented job in cron job.Please help !! (2 Replies)
Discussion started by: netdbaind
2 Replies

4. Shell Programming and Scripting

Cron job fails with [DataDirect][ODBC lib] Connection not open error

Hi, When run the script directly...it executes as expected. But when put it in crontab the job fails with this error: Connection not open 08003: Connection not open Unable to connect to the database... how come it is not able to connect when cron job fires?... Do I need to... (7 Replies)
Discussion started by: nuthakki
7 Replies

5. Solaris

Cron job running even after cron is removed

Hi , I have removed a cron for particular user , but cron job seems to be running even after the cron entry is removed. The purpose of the cron was to sendmail to user ( it uses mailx utility ) I have restarted cron and sendmail service still user is getting mail alerts from the cron job. And... (4 Replies)
Discussion started by: chidori
4 Replies

6. Solaris

Shell Script gives error when run through cron job.

Hi, The following shell script runs without any problem when executed manulally. USED=$(df -h /arch | tail -1 | awk '{print $5}' | cut -d '%' -f 1) if then find /arch/AUBUAT/ -type f -mtime +0 | xargs rm find /arch/AUBMIG/ -type f -mtime +0 | xargs rm fi But the same gives below... (6 Replies)
Discussion started by: ksadiq79
6 Replies

7. Shell Programming and Scripting

cron job error

HI am having a script file which is ok if i run from the server manually like <root@hostname:/space/canvas/home/lbs/current/internalcdrbackup/LES_CDR_Configuration/0/MSISDNcdrCount > /space/canvas/home/lbs/current/internalcdrbackup/LES_CDR_Configuration/0/MSISDNcdrCount.txt the... (2 Replies)
Discussion started by: aemunathan
2 Replies

8. UNIX for Dummies Questions & Answers

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... (1 Reply)
Discussion started by: shruthinagaraj
1 Replies

9. Shell Programming and Scripting

Cron job giving error while running SSH command

Hi All, The script which i am using to SSH to remote server is working fine when i run is using ./ but when cron runs it it gives error that "ssh: not found" please help!!! (3 Replies)
Discussion started by: visingha
3 Replies

10. Solaris

cron job starts new cron proccess

I run cron in solaris 10 zone. One cron job which syncing files to nfs mounted on container, creates after finishing another cron proccess(/usr/sbin/cron), and after 100 existing cron proccesses next cron job will not start. It's too weird for me, I'm not able to solve this problem. Theoretically... (3 Replies)
Discussion started by: ron76
3 Replies
Login or Register to Ask a Question