crontab里执行shell找不到db2数据库

AIX UNIX

下得先执行

crontab -e 编辑后

再执行

crontab -l 查看,

要是先执行crontab -l 会报错,

报错

SQL1013N  The database alias name or database name "DBNAME" could not be found.

解决办法

在脚本里加入执行.profile,加入“环境变量”

. /home/test/.profile

注意,前面是点空格

.profile里加入内容

PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:$HOME/bin:/usr/bin/X11:/sbin:.

export PATH

if [ -s "$MAIL" ]           # This is at Shell startup.  In normal

then echo "$MAILMSG"        # operation, the Shell checks

fi                          # periodically.

if [ -f /home/db2inst1/sqllib/db2profile ]; then

    . /home/db2inst1/sqllib/db2profile

fi

在脚本里可加入

id #查看当前用户

whoami  #查看当前用户

pwd #查看当前路径

猜你喜欢

转载自happyqing.iteye.com/blog/2352849