0

I have an bash script that will run db2 command (list active databases) and redirect the output to a file then I will use this file in another script.

Script:

/DB2RM1/db2rm1/sqllib/bin/db2 list active databases > /home/occddma/scripts/data

Note: I have put the location to the binaries of db2 before the db2 command to able to run it from crontab.

Then I put the script in crontab job to update datadb file every minute as shown below.

* * * * * /DB2RM1/db2rm1/mon_db2.sh

When I run the script form the command line it works fine but when it runs from the crotab job it redirects the below error to datadb file.

SQL10007N Message "-1390" could not be retrieved.  Reason code: "3".
2
  • How are you running this command via CLI? And what account is the cron set up for? Commented Jan 3, 2017 at 16:04
  • i run the script by ./script_name it works fine and update the datadb file while the cronjob is added to db2inst1 user crontab which have the script located in its home directory Commented Jan 3, 2017 at 17:09

2 Answers 2

1

You have not charge the db2profile. This file is in the sqllib directory of the instance's home directory.

Let's suppose your instance is db2inst1, then you need to call:

. ~db2inst1/sqllib/db2profile

Once the db2profile is loaded, you can see the value of the DB2INSTANCE environment variable.

One way to check if the environment is correctly loaded is to check if the DB2INSTANCE is set.

if [[ -z ${DB2INSTANCE} ]] ; then
   echo "ERROR"
   exit 1
fi

BTW, the 1390 is this error:

SQL1390C The environment variable DB2INSTANCE is not defined or is invalid.

Sign up to request clarification or add additional context in comments.

Comments

0

Most probably you have to load your bash profile in your script. Like:

source /etc/profile

or

source ~/.bash_profile

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.