签到成功

知道了

CNDBA社区CNDBA社区

zabbix监控oracle用户过期脚本报错Value

2023-03-22 22:36 935 0 原创 oracle
作者: hbhe0316

使用zabbix监控定制化脚本http://www.cndba.cn/hbhe0316/article/116502http://www.cndba.cn/hbhe0316/article/116502

http://www.cndba.cn/hbhe0316/article/116502

[root@agent zabbix]# cat zabbix_agentd.conf | grep Server | grep -v "#"
Server=192.168.56.110
ServerActive=192.168.56.110
[root@agent zabbix]# cat zabbix_agentd.conf | grep UnsafeUserParameters | grep -v "#"
UnsafeUserParameters=1
[root@agent zabbix]# cat zabbix_agentd.conf | grep -w UserParameter | grep -v "#"
UserParameter=FileCount, sudo /home/oracle/check_oracle_expired_time.sh

zabbix在执行脚本的时候会使用zabbix用户,所以在执行Oracle脚本的时候,需要将zabbix用户加入倒/etc/sudoers文件中,使得在执行的时候使用

#su - zabbix
#sudo /home/oracle/check_oracle_expired_time.sh (这里不应该输入zabbix用户的密码)

脚本具体内容http://www.cndba.cn/hbhe0316/article/116502

[root@test scripts]# cat check_oracle_expired_time.sh
#!/usr/bin/ksh
###############################################################################################################
# Script name: check_oracle_expired_time.sh
# Script description: check oracle username expired time
# Current Release Version: 1.0.0
# Script Owner: hbhe0316
# Latest editor: hbhe0316
# Support platform:  Linux OS for Linux.
# Change log: None
# Description:Date 2023/3/21
#
#
###############################################################################################################

checkFileExist(){
       if [[ -f /tmp/tmp_check_oracle_expired_time.out ]];then
               out_log="/tmp/tmp_check_oracle_expired_time.out"
       else
               touch /tmp/tmp_check_oracle_expired_time.out
               out_log="/tmp/tmp_check_oracle_expired_time.out"
       fi
                chmod 777 $out_log
}

checkExecuteUser(){
        username=`whoami`
        if [[ $username == "root" ]];then
                continue
        else
                echo "Current excute user is not oracle."
                exit 1
        fi
}

getExpiredDate(){
        su - oracle -c "sqlplus -S system/xxxxx@xx.xx.xxx.xxx:1521/orcl >$out_log << EOF
        set head off
        set feed off
        set lin 100 pages 2000
        select substr(username,0,10),substr(trunc(expiry_date - sysdate),0,10) from dba_users where username IN ('xxx','xxx','xxx','xxx','xxx');
        exit;
EOF
"
}


checkExecuteDate(){
        cat $out_log |  grep -v "^[[:space:]]*#" | sed 's/[[:space:]][[:space:]]*/    /g' | grep -v "^[[:space:]]*$" | while read line
        do
                expired_user=`echo $line |  grep -v "^[[:space:]]*#" | sed 's/[[:space:]][[:space:]]*/    /g' | grep -v "^[[:space:]]*$"  | awk -F ' ' '{print $1}'`
                expired_date=`echo $line |  grep -v "^[[:space:]]*#" | sed 's/[[:space:]][[:space:]]*/    /g' | grep -v "^[[:space:]]*$"  | awk -F ' ' '{print $2}'`
                if [[ ${expired_date} -lt 170 ]];then
                        echo "1"
#                       echo "'xxx','xxx','xxx','xxx','xxx' may expired"
                        exit 1
#                       echo "${expired_user} is small than ${expired_date}"
                else
                        echo 0
                        #echo "${expired_user} is bigger than ${expired_date}"
                fi
        done
}

main(){
    checkFileExist
        checkExecuteUser
        getExpiredDate
        checkExecuteDate
}

main

报错内容:

http://www.cndba.cn/hbhe0316/article/116502
http://www.cndba.cn/hbhe0316/article/116502

Value of type "string" is not suitable for value type "Numeric (unsigned)". Value "stty: standard input: Inappropriate ioctl for device
1"

最后在/home/oracle/.bash_profile 找到了答案,

http://www.cndba.cn/hbhe0316/article/116502
http://www.cndba.cn/hbhe0316/article/116502

#cat /home/oracle/.bash_profile | grep -i stty
stty erase ^h

删除.bash_profile文件中的stty erase ^h

http://www.cndba.cn/hbhe0316/article/116502
http://www.cndba.cn/hbhe0316/article/116502

su - oracle
. .bash_profile

版权声明:本文为博主原创文章,未经博主允许不得转载。

oracle

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
hbhe0316

hbhe0316

关注

1.只有承认无知,才能装下新的东西; 2.进步来自一点点滴滴的积累; 3.广博让你更优秀,而专业让你无法替代; 4.挫折和失败能够转换为一种财富。

  • 889
    原创
  • 1
    翻译
  • 13
    转载
  • 24
    评论
  • 访问:1143968次
  • 积分:1523
  • 等级:核心会员
  • 排名:第6名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ