db2上的Bash脚本 [英] Bash script on db2

查看:374
本文介绍了db2上的Bash脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个bash脚本,它将运行db2命令(列出活动数据库)并将输出重定向到一个文件,然后我将在另一个脚本中使用此文件。

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.

脚本:

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

注意:我把位置放到db2的二进制文件

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

然后我将脚本放在crontab作业中,每分钟更新datadb文件,如下所示。

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

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

当我从命令行运行脚本时,它工作正常,但当它运行从crotab工作,它将以下错误重定向到datadb文件。

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".


推荐答案

让我们假设你的实例是db2inst1,然后你需要调用:

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

. ~db2inst1/sqllib/db2profile

装入db2profile后,可以看到DB2INSTANCE环境的值变量。

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

检查环境是否正确加载的一种方法是检查是否设置了DB2INSTANCE。

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

,1390是这个错误:

BTW, the 1390 is this error:

SQL1390C环境变量DB2INSTANCE未定义或
无效。

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

这篇关于db2上的Bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆