Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.


Search this Thread
Old 04-12-2007, 05:49 PM   #1
Registered: Oct 2005
Location: Tierra Firma, Earth
Distribution: Debian of course...
Posts: 196

Rep: Reputation: 30
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)

Last edited by beeblequix; 04-12-2007 at 05:51 PM.
Old 04-12-2007, 07:32 PM   #2
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
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.
Old 04-13-2007, 11:22 AM   #3
Registered: Oct 2005
Location: Tierra Firma, Earth
Distribution: Debian of course...
Posts: 196

Original Poster
Rep: Reputation: 30

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.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Seting cron to run a script every second Rinish Programming 14 09-23-2010 03:48 AM
script does not run in cron job kashyapvirgo Linux - General 8 03-20-2007 11:55 AM
FTP Script will not run from Cron grhansen Programming 12 01-13-2006 05:13 AM
run shell script on cron varunbihani Linux - Newbie 5 07-08-2005 02:50 AM
can't get cron to run my script. dr_zayus69 Linux - Software 6 04-12-2005 07:34 PM

All times are GMT -5. The time now is 08:56 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration