LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Password
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.

Notices


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

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:
today.sh --
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)...
#!/bin/bash
...
indate=`cat /home/myuser/today.txt`
...

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

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.

Problem:
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.

Question:
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:
2.4.19-3suse-SMP
(31bit zSeries)


ß

Last edited by beeblequix; 04-12-2007 at 04:51 PM.
 
Old 04-12-2007, 06:32 PM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
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, 10:22 AM   #3
beeblequix
Member
 
Registered: Oct 2005
Location: Tierra Firma, Earth
Distribution: Debian of course...
Posts: 198

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
/home/db2inst1/sqllib/bin/db2

(DB2 is IBM's database)

I then put that at the top of my sript:
PATH=/home/db2inst1/sqllib/bin/db2

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.

ß
 
  


Reply



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 02:48 AM
script does not run in cron job kashyapvirgo Linux - General 8 03-20-2007 10:55 AM
FTP Script will not run from Cron grhansen Programming 12 01-13-2006 04:13 AM
run shell script on cron varunbihani Linux - Newbie 5 07-08-2005 01:50 AM
can't get cron to run my script. dr_zayus69 Linux - Software 6 04-12-2005 06:34 PM

LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise

All times are GMT -5. The time now is 09:21 PM.

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