cls_oracle_logs.sh脚本遭遇TNS-12508错误浅析
2024-04-23 17:18 潇湘隐者 阅读(54) 评论(0) 编辑 收藏 举报cls_oracle_logs.sh脚本的输出日志中有TNS-12508错误,具体如下所示
........................................................................
LSNRCTL> Current Listener is gsp
LSNRCTL> Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=gsp)))
TNS-12508: TNS:listener could not resolve the COMMAND given
LSNRCTL> LSNR_TRC_DIR: /opt/oracle19c/product/19.3.0/db_1/network/trace/
........................................................................
调试跟踪发现,脚本在切割监听日志时,执行命令set log_status off/set log_status on时报TNS-12508错误,部分脚本如下所示:
# Function used to cut log files.
f_cutlog(){
# Set name of log file.
LOG_FILE=$1
CUT_FILE=${LOG_FILE}.${TODAY}
FILESIZE=`ls -l $LOG_FILE | awk '{print $5}'`
# Cut the log file if it has not been cut today.
if [ -f $CUT_FILE ]; then
echo "Log Already Cut Today: $CUT_FILE"
elif [ ! -f $LOG_FILE ]; then
echo "Log File Does Not Exist: $LOG_FILE"
elif [ $FILESIZE -eq 0 ]; then
echo "Log File Has Zero Size: $LOG_FILE"
else
# Cut file.
echo "Cutting Log File: $LOG_FILE"
$MV $LOG_FILE $CUT_FILE
$TOUCH $LOG_FILE
fi
}
.....................................
# See if the listener is logging.
if [ -z "$LSNRLOG" ]; then
echo "Listener Logging is OFF. Not rotating the listener log."
# See if the listener log exists.
elif [ ! -r "$LSNRLOG" ]; then
echo "Listener Log Does Not Exist: $LSNRLOG"
# See if the listener log has been cut today.
elif [ -f $LSNRLOG.$TODAY ]; then
echo "Listener Log Already Cut Today: $LSNRLOG.$TODAY"
# Cut the listener log if the previous two conditions were not met.
else
# Disable logging.
$LSNRCTL <<EOF
set current_listener $LSNRNAME
set log_status off
EOF
# Cut the listener log file.
f_cutlog $LSNRLOG
# Enable logging.
$LSNRCTL <<EOF
set current_listener $LSNRNAME
set log_status on
EOF
# Delete old listener logs.
f_deletelog $LSNRLOG $NDAYS
fi
...................................
如下测试所示
LSNRCTL> set current_listener gsp
Current Listener is gsp
LSNRCTL> set log_status off
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=REGISTER_gsp)))
TNS-12508: TNS:listener could not resolve the COMMAND given
出现这个现象,是因为我们在监听参数文件listener.ora中设置了参数ADMIN_RESTRICTIONS_<listener_name>
ADMIN_RESTRICTIONS_GSP = ON
ADMIN_RESTRICTIONS_<listener_name>参数是一个重要的安全选项,在listener.ora文件中设置ADMIN_RESTRICTIONS_<listener_name>为ON时, 此后所有在运行时对监听器的修改都将会被阻止,所有对监听器的修改都必须通过手工修改listener.ora文件才能顺利完成。
Setting ADMIN_RESTRICTIONS_<listener_name> = ON disables the "runtime" modification of parameters in the listener.ora file.
In other words, the listener refuses to accept SET commands that alter its parameters and states that it cannot "resolve the COMMAND given."
脚本cls_oracle_logs.sh中,暂停监听器写入日志,完成监听日志的切换后,然后启用监听器写入日志。但是由于参数ADMIN_RESTRICTIONS_<listener_name>为ON的话 这里就会出现异常,那么我们修改脚本的逻辑,如果发现参数ADMIN_RESTRICTIONS_<listener_name>启用为ON的情况下,就将监听日志的内容拷贝到另外一个文件, 然后将当前的监听日志清空,具体代码如下所示:
# Function used to cut log files.
f_cutlog(){
# Set name of log file.
LOG_FILE=$1
PAR_ADMIN_RESTRICTIONS=$2
CUT_FILE=${LOG_FILE}.${TODAY}
FILESIZE=`ls -l $LOG_FILE | awk '{print $5}'`
# Cut the log file if it has not been cut today.
if [ -f $CUT_FILE ]; then
echo "Log Already Cut Today: $CUT_FILE"
elif [ ! -f $LOG_FILE ]; then
echo "Log File Does Not Exist: $LOG_FILE"
elif [ $FILESIZE -eq 0 ]; then
echo "Log File Has Zero Size: $LOG_FILE"
else
# Cut file.
if [ [$PAR_ADMIN_RESTRICTIONS == 'ON' ]] || [[ $PAR_ADMIN_RESTRICTIONS == 'on' ]];then
# Cut file.
echo "Cutting Log File: $LOG_FILE"
cat $LOG_FILE > $CUT_FILE
cat /dev/null > $LOG_FILE
else
echo "Cutting Log File: $LOG_FILE"
$MV $LOG_FILE $CUT_FILE
$TOUCH $LOG_FILE
fi
fi
}
......................................................
# See if the listener is logging.
if [ -z "$LSNRLOG" ]; then
echo "Listener Logging is OFF. Not rotating the listener log."
# See if the listener log exists.
elif [ ! -r "$LSNRLOG" ]; then
echo "Listener Log Does Not Exist: $LSNRLOG"
# See if the listener log has been cut today.
elif [ -f $LSNRLOG.$TODAY ]; then
echo "Listener Log Already Cut Today: $LSNRLOG.$TODAY"
# Cut the listener log if the previous two conditions were not met.
else
# 加上head -1 主要是防止出现两个名字很接近的监听,例如下面配置,就会得到两个值
# ADMIN_RESTRICTIONS_gspprod = ON
# ADMIN_RESTRICTIONS_gspprodro = ON
LSN_ADMIN_RESTRICTIONS=`cat $LSNPARAM | grep -i "ADMIN_RESTRICTIONS_$LSNRNAME" | awk '{print $3}' |head -1`
if [[ $LSN_ADMIN_RESTRICTIONS == "ON" ]] || [[ $LSN_ADMIN_RESTRICTIONS == "on" ]];then
f_cutlog $LSNRLOG $LSN_ADMIN_RESTRICTIONS
else
# Disable logging.
$LSNRCTL <<EOF
set current_listener $LSNRNAME
set log_status off
EOF
# Cut the listener log file.
f_cutlog $LSNRLOG $LSN_ADMIN_RESTRICTIONS
# Enable logging.
$LSNRCTL <<EOF
set current_listener $LSNRNAME
set log_status on
EOF
fi
# Delete old listener logs.
f_deletelog $LSNRLOG $NDAYS
fi
......................................................
扫描上面二维码关注我
如果你真心觉得文章写得不错,而且对你有所帮助,那就不妨帮忙“推荐"一下,您的“推荐”和”打赏“将是我最大的写作动力!
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接.