-   Linux - Enterprise (
-   -   can run script from my user but not with cron (

beeblequix 04-12-2007 05:49 PM

can run script from my user but not with cron
overall goal:
have my nu_ext_nt3.bash script run daily with zero human intervention, and eventually handle it's own ftp as well.

components: --
Initiated by my user's crontab which simply takes a snapshot of whatever 'today' is and sends it into a .txt file in "yyyy-mm-dd" format. This info is then going to be used the next calendar date as input like this (note elipses just indicate there's much more in the script that's not that important here)...
indate=`cat /home/myuser/today.txt`

I've entered this script in my crontab and it works --
crontab -e
mm dd * * * sh /home/myuser/

nu_ext_nt3.bash --
This script is far more complex. It's a combination of two other scripts that originally needed manual date input from either the cmd line (ie, scriptname yyyy-mm-dd) or in the other script's case from the "read indate" type of command.

This first 'half' used to take the date from cmd line, which would then utilize the "$1" variable to pass it through the rest of the script. This half of the script requires that it logs from the linux guest into DB2 and run sql queries to pull certain data from a table and pass that data through its own ~general application~ process which would then produce a file under the directory in which it ran. Now I'm using the today.txt mentioned above.

The second part of the script would similarly log into the same DB2 and run a different query on that same table to count number of transactions in that table, then export a different report which I've specified with variables to hopefully make it easier (ie, outfile=/home/myuser/numtrans/numtrans.${indate}.txt). I'd then echo my sql queries into that file in a certain order which creates a number of transactions for that calendar date broken down by hour.

I've made different versions: separate which require separate human input, one that prompts the user to input date once inside the script (read indate), one that's run the next day manually which simply takes the data stored in today.txt and passes that through my script creating both output files. Being that I'm lazy & all I want cron to start pulling its weight around here and just run the thing.

I've therefore tried testing this by adding a line to my crontab to run my newer nu_ext_nt3.bash script.

cron seems to have serious trouble logging into DB2 for me. My user keeps getting emails telling me a number of 'command not found' complaints. The first in the email is
/home/myuser/nu_ext_nt3.bash: line 74: db2: command not found (which is basically ~db2 connect to mytestdb2thingie user myuser using myuserpasswd -- I previously had it pulling these from environment variables but removed them to try to troubleshoot this).
I get a simliar message when it tries to 'set isolation ur' (which is suppose d to prevent locking a table)
then I get 25 lines of
/home/myuser/nu_ext_nt3.bash: line1: db2: command not found (which I THINK is just my script telling me that from within my bash sript the db2 part doesn't work for the 25 different queries).
then I get this error once
/home/myuser/nu_ext_nt3.bash: line155: db2: command not found (which is where I issue the 'db2 connect reset' command)
then finally this one
/home/myuser/nu_ext_nt3.bash: line 173: general_application_thingie: command not found)(it's not REALLY called that but it protects the innocent...)

I've read elsewhere that cron likes full paths, and I've at least arranged some of my script to output a correctly named numtrans.${indate}.txt file with the correct first column info (ie, 00:00 - 01:00,) (note: it's comma separated for ease of use with Excel). But I'm at a loss in getting my script to log into DB2 automagically.

How can I make cron run this script with the same success as my user? I'm *not* root if that helps. Ideas?

oh, uname -4:
(31bit zSeries) 04-12-2007 07:32 PM

Well, that's a long post, but it looks like bash is being asked to run something called "db2", and you're not providing the full path to db2.

beeblequix 04-13-2007 11:22 AM


It always seems like those little things get overlooked. Thanks. That helped. I wasn't sure where 'db2' was located but found it by doing this:
which db2

(DB2 is IBM's database)

I then put that at the top of my sript:

I tried again and had different errors, but at least it found my db2 executable. It complained something about not being able to cat, touch or mail from my script.

Then I decided to just try to make cron's PATH the same as my user. I didn't know a better way to do it so I just did this:
env > myuser_env.txt

Then added this to my script:
PATH=`cat /home/myuser/myuser_env.txt`

SOME JOY! My numtrans part worked! The other part could not find a specific shared object, but that's kinda weird since that .so is found inside the PATH...

I think at this point I'll divide the script out into two again and at least have one that works with cron. Eventually I'll get the other one working.

Thx for your help.

All times are GMT -5. The time now is 07:25 PM.