Auto start DB2 Sript

<password.exp>

#!/usr/bin/expect

set timeout 30

if { $argc != 1 } {
    send_user "/nusage: $argv0 start|stop|status/n"
    exit
}

if {[lindex $argv 0] == "start"} {
    set cmd "db2start"
} elseif {[lindex $argv 0] == "stop"} {
    set cmd "db2stop"
} elseif {[lindex $argv 0] == "status"} {
    set cmd "status"
} else {
    send_user "/nusage: $argv0 start|stop|status/n"
    exit
}

spawn su db2inst1
expect {
    "Password:*" {
        send "admin/r"
        expect "*db2inst1*"
     }
    {db2inst1*/>} {send_user "/nIt's root path/n"}
}

#set timeout 5
#expect eof
set timeout 30

send "ps -ef/r"
expect {
{db2sysc} {
       if {$cmd == "db2stop"} {
           send "$cmd/r"
           expect {
              "*DB2STOP processing was successful*" { send_user "/ndb2 has been stopped/n"; exit 2}
              "*No start database manager command was issued*" {send_user "/nNo start database manager command was issued/n"; exit 2}
              timeout { send_user "/nunknown status/n"}
           }
       } else {
           send_user "/ndb2 has been active/n"
           exit 1
       }
    }
{db2inst1*/>} {
       if {$cmd == "db2start"} {
           send "db2start/r"
           expect {
               "*DB2START processing was successful*" { send_user "/ndb2 is starting/n"; exit 1}
               "*The database manager is already active*" { send_user "/nThe database manager is already active/n"; exit 1}
               timeout { send_user "/nunknown status/n"; exit 255}
           }
       } else {
           send_user "/ndb2 has been stopped/n"
           exit 2
       }
    }
timeout {send_user "/ncan't find db2 process, timeout./n"; exit 255}
}

exit

<autodb2start.sh>

#!/bin/bash

#DB2_HOME=/opt/ibm/db2/V9.7/bin
#User=db2inst1

# login with su db2inst1
#./password.exp status

case $1 in
start)
    ./password.exp start
    echo "`date`: test db2 start" >> /tmp/db2start888888888888888
    ;;
stop)
    ./password.exp stop
    echo "`date`: test db2 stop" >> /tmp/db2start888888888888888
    ;;
status)
    ./password.exp status
    echo "`date`: test db2 status" >> /tmp/db2start888888888888888
    ;;
*) echo "Usage: `basename $0` (start|stop|status)"
    ;;
esac

 

copy these two files to /etc/init.d/autodb2start, and /etc/init.d/password.exp.

 

/sbin/chkconfig --list | grep autodb2start
autodb2start              0:off  1:off  2:off  3:off  4:off  5:off   6:off

 

Run command:

/sbin/chkconfig --level 5 autodb2start on

 

/sbin/chkconfig --list | grep autodb2start
autodb2start              0:off  1:off  2:off  3:off  4:off  5:on   6:off

 

Now it will run automatedly.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值