Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UNIX commands won't execute under Cron 2

Status
Not open for further replies.

MrJRW

IS-IT--Management
Feb 6, 2002
47
US
Good Afternoon.
This one has me scratching my head.
I have a Sybase data server running on a HP-UNIX host.
I've created a script that backups up the databases on the Sybase server.
When executed MANUALLY, the script runs fine.
Before doing the backups, the script deletes the earliest backup from the directory.
BUT....
When I use cron the execute the script, PROBLEMS !

The script is as follows: (just a few lines)
#!/bin/sh
. /sybase/STG_12.0/SYBASE.sh

START_DT=`date`
export START_DT
echo "Start: $START_DT"

cd /sybase/backups/stage/dumps


# Remove the earliest backups from the directory

OLDCMSPRODFILE=`ls -lt cms_prod_dump.*|tail -1|cut -c60-84
export OLDCMSPRODFILE
rm $OLDCMSPRODFILE
etc....

When the script is run via cron I get the following:

/sybase/backup/stage/scripts/CMS_STG_BACKUP[4]: date: not found.
Start:
/sybase/backup/stage/scripts/CMS_STG_BACKUP[13]: ls: not found.
/sybase/backup/stage/scripts/CMS_STG_BACKUP[13]: tail: not found.
/sybase/backup/stage/scripts/CMS_STG_BACKUP[13]: cut: not found.
/sybase/backup/stage/scripts/CMS_STG_BACKUP[15]: rm: not found.
etc....

Any ideas ??
JRW
 
cron is notorious for a minimal default environment.

Make sure your environment variables as set in your interactive session (especially PATH) are explicitly set in your cron script.
 
MadMichael,
Thank-you for responding so quickly.
I'm a little confused.

When I run the script manually, I'm logged in to UNIX as sybase.

This entry IS in the user sybase's crontab (/usr/spool/cron/crontab/sybase

Shouldn't being in sybase's crontab already confer the attributes of the sybase login ?

JRW
 
Basically, no. As MadMichael advises, cron is notorious for this kind of behaviour.

Make sure your PATH is set explicitly within the script, and reflects that from and echo $PATH command when logged in as the Sybase user. You can also use the full path to things like date to be extra sure, but a properly set PATH should obviate this.

Let us know how you get on.

I want to be good, is that not enough?
 
O.K.
Is there a something I can execute (.profile ?, .login ?)that will set the various environment variables that need to be set ?

JRW
 
Thank-you all. My problem has been solved !

My solution was to add two (2) lines after the SYBASE.sh script:

#!/bin/sh
. /sybase/STG_12.0/SYBASE.sh

<<<<<< New lines added here >>>>>>>

PATH=/usr/bin:$PATH
export PATH


START_DT....

O.K. to close.
JRW
 
Good stuff, JRW, and thanks for the star! Incidentally, your solution could be modded to one line thus:

export PATH=/usr/bin:$PATH

combining the export with the definition.

I want to be good, is that not enough?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top