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

我使用的语句是case 语句

case     变量值     in

创新互联专注于企业成都营销网站建设、网站重做改版、浑江网站定制设计、自适应品牌网站建设、成都h5网站建设商城网站开发、集团公司官网建设、成都外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为浑江等各大城市提供网站开发制作服务。

              模式1)

                     命令序列1

                     ;;

              模式2)

                     命令序列2

                     ;;

                     ……

                     *)  

                     默认命令序列

 esac

以下是脚本

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

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

restart)
sqlplus -s /nolog > /dev/null <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 <   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


网页标题:shell脚本启动、关闭、重启以及查看状态
文章出自:http://pwwzsj.com/article/psgics.html