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文件才能顺利完成。文章来源:https://www.toymoban.com/news/detail-856677.html
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的情况下,就将监听日志的内容拷贝到另外一个文件, 然后将当前的监听日志清空,具体代码如下所示:文章来源地址https://www.toymoban.com/news/detail-856677.html
# 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
......................................................
到了这里,关于cls_oracle_logs.sh脚本遭遇TNS-12508错误浅析的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!