我使用的语句是case 语句 case 变量值 in  
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
--结束END--
本文标题: shell脚本启动、关闭、重启以及查看状态
本文链接: https://lsjlt.com/news/49154.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0