ITPub博客

shell脚本启动、关闭、重启以及查看状态

原创 Oracle 作者:波仔strong 时间:2018-02-06 19:23:28 0 删除 编辑
我使用的语句是case 语句

case     变量值     in

              模式1

                     命令序列1

                     ;;

              模式2

                     命令序列2

                     ;;

                     ……

                     *  

                     默认命令序列

 esac

以下是脚本

#! /bin/bash
case "$1" in
start)
sqlplus -s /nolog > /dev/null  <<eof
conn / as sysdba
startup
exit;
EOF
echo "Database openned."
;;

stop)
sqlplus -s /nolog > /dev/null <<eof
conn / as sysdba
shutdown immediate
exit
EOF
echo "Database stopped."
;;

restart)
sqlplus -s /nolog > /dev/null <<eof
conn / as sysdba
shutdown immediate
startup
exit
EOF
echo "Database restarted."
;;

status)
pmonstat=`ps -ef | grep ora_pmon | grep -v grep | wc -l`
if [ $pmonstat -gt 0 ]
then
   dbstatus=`sqlplus -s /nolog <<eof
   conn / as sysdba
   set feedback off heading off pagesize 0
   select status from v\\$instance;
   exit
EOF`
  echo "Database status:$dbstatus"
else
  echo "Database not started."
fi
;;

*)
  echo "----------------------------------------"
   echo "Usage: start, stop, status, restart"
  echo "----------------------------------------"
;;
esac

</eof
</eof
</eof
</eof

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31485142/viewspace-2150906/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2017-08-25

  • 博文量
    87
  • 访问量
    35031