使用zabbix监控定制化脚本
[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用户的密码)
脚本具体内容
[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
报错内容:
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 找到了答案,
#cat /home/oracle/.bash_profile | grep -i stty
stty erase ^h
删除.bash_profile文件中的stty erase ^h
su - oracle
. .bash_profile
版权声明:本文为博主原创文章,未经博主允许不得转载。
oracle