Running bteq scripts through crontab

Database
Enthusiast

Running bteq scripts through crontab

Hi All,

I want to execute a shell script 'abc.sh' that contains --->

*********
bteq < /a123b/scripts/abc.btq >> /a123b/scripts/hello1.log 2 >> /a123b/scripts/hello1.log
*********

abc.btq is a bteq file containing some teradata bteq statements.
The problem here is that this shell script runs absolutely fine if i execute it manually proving the fact that abc.btq is correct .
The output is a log file containing the statement 'successful'

But when i inserted the same shell script in crontab(a scheduler in unix) to execute it at a specific time everyday, it doesn't run.

My crontab entry looks like this:

* * * * * /a123b/scripts/abc.sh >> /a123b/scripts/hello1.log 2 >> /a123b/scripts/hello1.log

Hence the result is a log file of size 0 bytes.
This brings me to the conclusion that the crontab can never execute a bteq script?.
Can anybody help me out with this problem as to how to execute a bteq file using crontab
6 REPLIES

Re: Running bteq scripts through crontab

Hello,

Crontab is essentially, what I call "dumb", meaning that it does not automatically source in your profile.

In your crontab entry you can insert the following before your existing crontab enter: "/your user home path/.profile;"

So your crontab entry would look like:
* * * * * /your user home path/.profile; /a123b/scripts/abc.sh >> /a123b/scripts/hello1.log 2 >> /a123b/scripts/hello1.log

or you can do this atop each of your shell (ksh/sh) scripts.

Also for crontab, or any other scheduling software that I've used, it's better to fully qualify your paths to all commands within all scripts.

BoB
Enthusiast

Re: Running bteq scripts through crontab

To add a bit, you may want to use the . (dot) operator as well.

* * * * * . $HOME/.profile; /a123b/scripts/abc.sh >> /a123b/scripts/hello1.log 2>&1

Enthusiast

Re: Running bteq scripts through crontab

su - username -c "/a123b/scripts/abc.sh >> /a123b/scripts/hello1.log 2>&1 "

As crontab is for system level, use user-root's environment
:-)
Hope may be useful .
Years ago when i elt data ,met with the same questions :-)
you should also learn more about OS

Teradata Employee

Re: Running bteq scripts through crontab

Hello,

I am running bteq through shell script. When I ran shell script manually it worked as expected.

when I tried of running same script through crontab, script is running but bteq not executing at all.

Where am I making mistake?

Anyone could help me out here?

crontab entry:

49 15 * * 1 /usr/bin/sh /home/support/DBQLogs/DBQLogexp_del.sh  >> /home/support/DBQLogs/DBQLogexp_del_log.txt 2>&1

script:

date=$(date +"%d-%m-%y")

time1=$(date +"%T")

echo "================================================="

echo -e "\n\nbteq going to execute..Please wait...."
echo "================================================="

/opt/teradata/client/15.10/bin/bteq << EOF > DBQLog.txt

.LOGON sdlc6382.labs.teradata.com/dbc,dbc;

...

...

...

.LOGOFF;

.EXIT;

Teradata Employee

Re: Running bteq scripts through crontab

Did you not read the posts above? When cron runs your script, it does not source your user profile. Some options are given above, or Google search for cron profile environment to see some other ideas.

Teradata Employee

Re: Running bteq scripts through crontab

Thanks fred ..

your suggestion to search on google gave me some clear idea about cron environment.

And above options helped me lot..