Troubles running DB2 command in shell script via cron


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Troubles running DB2 command in shell script via cron
# 1  
Old 12-08-2016
Troubles running DB2 command in shell script via cron

Hi there,

Now I'm facing error regarding running shell script via cron.

The shell script which is required to get value from database.
Below is the main part of shell script.

Code:
#/bin/bash

#connect to database(1)
db2 connect to $database user xxxx using yyyy

#set values from database(2)
status=`db2 -x select status from TABLE_X where end_date = select max(end_date) from TABLE_X`

#rest of the process(3)
if [ ${status} -eq 2 ]; then
  echo 'SUCCESS'
  process to next step

elif [ ${status} -eq 1 ]; then
  'WARNING'
  exit 2

else
  echo 'FATAL'
  exit 99

fi

process (1) success, but process (2) doesn't work when run this script via cron, so process (3) always exit with FATAL.

It works properly when run this manually.

I try some solutions:

* edit crontab settings

(before)
Code:
*/10 * * * * /home/aaa/bbb/PPAP.sh

(after)
Code:
*/10 * * * * /bin/bash -l /home/aaa/bbb/PPAP.sh

* run db2profile in shell script

I reffered the relate topic and try that, but error still exists...Smilie
Code:
ttp://dba.stackexchange.com/questions/91807/online-backup-is-not-performed-from-the-cron-job-on-linux-server-manually-it-wo

Somebody has idea??

Thank you in advance.



Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by rbatte1; 12-08-2016 at 07:35 AM.. Reason: Added CODE tags.
# 2  
Old 12-08-2016
Sounds like this has been solved before.
Look into the links at the bottom of this page.
# 3  
Old 12-08-2016
I checked the link, and fix my script. It works properly now. Thank you for noticingSmilie

By the way, why
Code:
status=`db2 -x select status from TABLE_X where end_date = select max(end_date) from TABLE_X`

this script above doesn't work when executed by cron?
# 4  
Old 12-08-2016
Quote:
Originally Posted by Rohan Kishibe
I checked the link, and fix my script. It works properly now. Thank you for noticingSmilie

By the way, why
Code:
status=`db2 -x select status from TABLE_X where end_date = select max(end_date) from TABLE_X`

this script above doesn't work when executed by cron?
It doesn't work because cron doesn't know how to set up your environment like your shell does. When you log in, your shell initializes your environment with settings that allow your database commands to be found without specifying absolute pathnames for the database utilities and includes settings specifying what database to use and what access codes are needed to access that database. You have to make the script you run with cron make that same environment information available to the shell that is being run by cron.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Db2 command issues with cron

Hi, I have a very simple script that queries from a DB2 table. The script has 3 parts - (i) Sets the db2profile (ii) connects to db2 using credentials (iii) executes the query.This script works fine if i run it manually from the command prompt. However when scheduled in crontab, it proceeds... (2 Replies)
Discussion started by: VeePee
2 Replies

2. UNIX for Dummies Questions & Answers

Cron shell script not executing diskutil command

I'm trying to learn how to use cron for repetative tasks. I have an external disk that needs to be unmounted and remounted every hour due to some problems that a backup utility (specifically, TimeMachine) is having repeatedly accessing the device. I've created a shell script that will find the... (3 Replies)
Discussion started by: illuminate
3 Replies

3. Shell Programming and Scripting

Running shell script via cron

Hi Guys, I do have a shell script that I scheduled to run via the cron but when the script don't run. But when I run the script manually it does run perfectly... What might be the problem? Thanks. (1 Reply)
Discussion started by: Phuti
1 Replies

4. Shell Programming and Scripting

Running Shell Script in the cron, background process

Hi, i was looking for an answer for some trouble im having runing a script in the cron, thing is, that when i run it manually it works just fine. But when cron runs it, it just doenst work. I saw a reply on a similar subject, suggesting that the . .profile worked for you, but im kind of... (9 Replies)
Discussion started by: blacksteel1988
9 Replies

5. Shell Programming and Scripting

Running Shell Script in the cron, background proccess

Hi, i was looking for an answer for some trouble im having runing a script in the cron, thing is, that when i run it manually it works just fine. But when cron runs it, it just doenst work. I saw a reply on a similar subject, suggesting that the . .profile worked for you, but im kind of... (0 Replies)
Discussion started by: blacksteel1988
0 Replies

6. Shell Programming and Scripting

Troubles with shell script

Hello. I'm having trouble figuring out how to write this script. I'm supposed to have my script start up with specific arguments and if there are missing arguments or invalid arguments, return an error associated to its errorlevel number. For example, here are a few errorlevel numbers with their... (4 Replies)
Discussion started by: Simonpalmieri
4 Replies

7. Shell Programming and Scripting

URGENT: cron job not running the sqlplus command in shell script

cron job not running the sqlplus command in shell script but the shell script works fine from command line.. Cronjob: 5 * * * * /home/dreg/script.sh script.sh: #!/bin/ksh /oracle/u000/app/oracle/product/10204/GEN/bin/sqlplus -s <user>/<pass>@<sid/home/dreg/sqlscript.sh ... (18 Replies)
Discussion started by: Ikea
18 Replies

8. Shell Programming and Scripting

Running a shell script in cron...email not sending - help??

I am pretty new to Unix shell scripting, but wondered if anyone could help (in layman's terms if possible!!) :) I have a shell script which ultimately sends an alert to an email address if part of a batch of programs fails. Here's the script that sends the email: Script: 6check.csh... (8 Replies)
Discussion started by: tjhorwood
8 Replies

9. Shell Programming and Scripting

error in running shell script in cron

#!/bin/bash CLASSPATH=. #CLASSPATH=${CLASSPATH}:${INSTALL_PATH}home/squidlog/CopyFile.java CLASSPATH=${CLASSPATH}:${INSTALL_PATH}usr/java/latest/lib/*.jar javac CopyFile.java echo "CLASSPATH=$CLASSPATH" #home/wbiadmin/JRE1.4.2/j2re1.4.2_15/bin/java CopyFile /usr/bin/java... (3 Replies)
Discussion started by: sari
3 Replies

10. HP-UX

cron troubles

I have a cronjob that I need to run everyday and it needs to have todays date inputed, here is what I have, but is not working as expected.......... 23 02 * * * cd /path;./RequestSummaryReport.sh $(date +%Y-%m-%d) the output from mail gives me............. Date: Fri, 8 Feb 2008 02:12:07... (4 Replies)
Discussion started by: theninja
4 Replies
Login or Register to Ask a Question