LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-11-2013, 02:12 PM   #1
gacanepa
Member
 
Registered: May 2012
Location: San Luis, Argentina
Distribution: Debian
Posts: 203

Rep: Reputation: 27
Run bash script w/ sql queries using cron (RHEL 5.7, Oracle 11g)


Hi everyone,
I wrote a shell script that runs a couple of SQL queries (Oracle 11g), which in turn create a couple of *.csv files for later processing.
The script runs flawlessly if I execute it from the command line by hand.
So I tried to run it using cron:
Code:
PATH=/opt/das/common/util:/usr/bin:/bin
MAILTO=me@mydomain.com
53 15 * * * /home/me/ira_reports/ira.sh P me@mydomain.com
As you can see, I included the full path to the script, along with the 2 arguments that it requires (in this example, "P" and "me@mydomain.com".
I even added those 3 directories to cron's environment variable PATH, which is where all the executables called in my script are located, especifically:
Code:
me@mybox /home/me/ira_reports:which sql
/opt/das/common/util/sql
And I keep getting this error:
Code:
/opt/das/common/util/sql: line 37: /sqlplus.log: Permission denied
/opt/das/common/util/sql: line 39: sqlplus: command not found
/opt/das/common/util/sql: line 45: /sqlplus.log: Permission denied
I am not calling sqlplus in my script. Just plain sql exactly the way I do it from the command line.
FYI, in my script I source the *.sql files to the sql command like this (full path as well):
Code:
sql @/home/me/ira_reports/stkcnt.sql <<EOF
$itmcls
EOF
Needless to say, none of the sql queries get executed.
Unfortunately, I do not have the possibility to run these queries with an user with escalated privileges. But I don't think I'd need to anyway, considering that cron technically runs with the same privileges of the user who set up the crontab file, and as I said, I can run the script from the command line without any issues whatsoever.
Please feel free to correct me.
Any hints or ideas will be more than welcome. Thanks in advance!

Last edited by gacanepa; 10-11-2013 at 02:16 PM.
 
Old 10-12-2013, 07:49 AM   #2
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
looks like you have two problems

/sqlplus.log is on the root
and your script can't find sqlplus

in your script, use the full path to desired log location, and the sqlplus executable
 
Old 10-12-2013, 09:49 AM   #3
gacanepa
Member
 
Registered: May 2012
Location: San Luis, Argentina
Distribution: Debian
Posts: 203

Original Poster
Rep: Reputation: 27
I did, but still didn't work.
I eventually solved the issue by exporting all the environment variables that were available to my user session at the top of my script, so when the time came to actually execute the sql queries and stuff through cron, it worked like a charm (see complete solution here). So it was a environment issue.
Thank you very much for taking the time to reply to my post. I really appreciate it.
 
  


Reply

Tags
bash scripting, cron, oracle11g


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
Trying to install Oracle 11g on RHEL 5.2 louisb Linux - Enterprise 38 08-21-2014 01:38 PM
OpenLDAP in RHEL 4 ES and oracle 11g fadu Linux - Newbie 1 07-11-2010 12:43 PM
How to run SQL queries in Fedora-10 hemanthv414 Linux - Software 4 02-04-2009 06:53 PM
Bash script can't handle errors when run by cron rosv Programming 4 01-08-2009 07:50 PM
Run bash commands script as cron anjanesh Linux - General 4 04-03-2007 06:25 AM


All times are GMT -5. The time now is 10:12 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration