当前位置: 首页 > news >正文

Shell自动化管理 for ORACLE DBA

1.自动收集每天早上9点到晚上8点之间的AWR报告。 auto_awr.sh

#!/bin/bash# Set variables
ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1
ORACLE_SID=orcl
AWR_DIR=/home/oracle/AWR# Set date format for file naming
DATE=$(date +%Y%m%d%H%M%S)# Check current time - only run between 9am and 8pm
HOUR=$(date +%H)
if [[ "$HOUR" -lt 9 || "$HOUR" -ge 20 ]]; thenecho "Not within collection window. Exiting."exit
fi# Create AWR directory if it does not exist
mkdir -p $AWR_DIR# Run AWR report for the last hour
$ORACLE_HOME/bin/sqlplus / as sysdba <<EOF
set pagesize 0
set linesize 1000
set trimspool on
set feedback off
set echo off
define report_type='html'
define num_days=1
define begin_snap='${ORACLE_SID}_\${DATE}'
define end_snap='&begin_snap'
define dbid=''
define inst_num=''
define report_name='$AWR_DIR/awr_\${DATE}.html'
@?\rdbms\admin\awrrpt.sql
EOF

2.一个check_ccps.sh 检查待推送,监控上送,监控8999和返回代码为空的交易、检查是否对账、监控未对账。

可以执行以下检查:

  • 检查待推送交易
  • 监控上送交易
  • 监控8999返回代码为空的交易
  • 检查是否对账
  • 监控未对账的交易
#!/bin/bash# Set variables
LOG_DIR=/var/log/ccps
WORK_DIR=/opt/ccps
CHECK_DATE=$(date +%Y%m%d)# Check for pending transactions
PENDING_COUNT=$(grep -c "Pending transaction" $LOG_DIR/ccps_${CHECK_DATE}.log)
if [[ "$PENDING_COUNT" -gt 0 ]]; thenecho "There are $PENDING_COUNT pending transactions."
fi# Monitor submitted transactions
SUBMITTED_COUNT=$(grep -c "Submitted transaction" $LOG_DIR/ccps_${CHECK_DATE}.log)
if [[ "$SUBMITTED_COUNT" -gt 0 ]]; thenecho "There are $SUBMITTED_COUNT submitted transactions."
fi# Monitor 8999 response code
NO_RESPONSE_COUNT=$(grep -c "Response code: " $LOG_DIR/ccps_${CHECK_DATE}.log | grep -c "Response code: [[:space:]]*$")
if [[ "$NO_RESPONSE_COUNT" -gt 0 ]]; thenecho "There are $NO_RESPONSE_COUNT transactions with no response code."
fi# Check reconciliation status
RECON_STATUS=$(grep "Reconciliation completed" $LOG_DIR/ccps_${CHECK_DATE}.log | tail -n1)
if [[ -z "$RECON_STATUS" ]]; thenecho "Reconciliation has not been completed."
elseecho "Reconciliation has been completed."
fi# Monitor unreconciled transactions
UNRECONCILED_COUNT=$(find $WORK_DIR -name "*_${CHECK_DATE}.txt" | wc -l)
if [[ "$UNRECONCILED_COUNT" -gt 0 ]]; thenecho "There are $UNRECONCILED_COUNT unreconciled transactions."
fi

该脚本假定CCPS系统日志文件名为ccps_<DATE>.log,并且所有待处理的交易文件都保存在工作目录中。您需要根据实际情况更新变量LOG_DIRWORK_DIR

该脚本通过搜索日志文件中的特定字符串来执行各种检查,并在发现问题时输出相应的消息。例如,如果有待推送的交易,将输出类似于“有X个等待处理的交易”的消息。

请注意,此脚本只是一个示例,并且可能需要根据您的具体需求进行修改和自定义。

Tips:

CCPS是“跨行交换清算系统”的缩写,是中国人民银行推出的用于实现银行间资金结算、交易清算和风险控制的统一平台。其主要功能包括支付结算、融资融券、黄金业务等。

CCPS通过建立一个统一的、高效的资金交换和清算机制,为银行业提供了更加便捷、安全、高效的资金结算服务,同时还可以起到监管和风险防控的作用。它支持多种付款方式,包括即时支付、定向支付、批量代发等,并且具有实时处理、高可靠性和大容量的特点。

在CCPS系统中,各家银行通过网络与CCPS系统进行连接,完成资金交换和清算。在交易过程中,CCPS系统将根据规则对交易进行审核和结算,保证交易的合法性和安全性。同时,CCPS系统还提供了实时交易监控和风险控制服务,能够及时响应各类异常情况和风险事件。

总之,CCPS是中国银行业重要的基础设施之一,为实现快速、安全、高效的资金结算提供了必要的支持。

3.check_database.sh 检查数据库是否处于打开状态、控制文件和日志文件是否正常、表空间是否在线、以及数据文件是否备份。

check_database.sh脚本,可以监控Oracle数据库的各种状态:

#!/bin/bash# Set variables
ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1
ORACLE_SID=orcl
LOG_DIR=/var/log/oracle# Check database status
DB_STATUS=$(echo "select status from v\$instance;" | $ORACLE_HOME/bin/sqlplus -S / as sysdba)
if [[ "$DB_STATUS" != "OPEN" ]]; thenecho "Database is not open."
fi# Check control file status
CONTROL_STATUS=$($ORACLE_HOME/bin/sqlplus -S / as sysdba <<EOF
set heading off feedback off verify off
select status from v\$controlfile;
EOF
)
if [[ "$CONTROL_STATUS" != "ONLINE" ]]; thenecho "Control file is not online."
fi# Check log file status
LOG_STATUS=$($ORACLE_HOME/bin/sqlplus -S / as sysdba <<EOF
set heading off feedback off verify off
select status from v\$logfile;
EOF
)
if [[ "$LOG_STATUS" != "VALID" ]]; thenecho "Log file is not valid."
fi# Check tablespace status
TABLESPACE_ALERT=$($ORACLE_HOME/bin/sqlplus -S / as sysdba <<EOF
set heading off feedback off verify off
SELECT t.tablespace_name, t.status FROM dba_tablespaces t WHERE t.status NOT IN ('ONLINE', 'READ ONLY');
EOF
)
if [[ -n "$TABLESPACE_ALERT" ]]; thenecho "One or more tablespaces are not online:"echo "$TABLESPACE_ALERT"
fi# Check datafile status
DATAFILE_ALERT=$(find $ORACLE_HOME/dbs -name "*.dbf" -type f -mtime +7 -exec ls -l {} \;)
if [[ -n "$DATAFILE_ALERT" ]]; thenecho "One or more datafiles have not been backed up in the last 7 days:"echo "$DATAFILE_ALERT"
fi

该脚本通过运行SQL查询或查找文件来检查数据库的各种状态。例如,它会检查数据库是否处于打开状态、控制文件和日志文件是否正常、表空间是否在线、以及数据文件是否备份。

请注意,此脚本只是一个示例,并且您可能需要根据您的具体需求进行修改和自定义。特别是对于tablespace的status判断以及datafile的备份情况判断,您需要根据实际情况来调整相应的阈值和条件。

4. 登录监控,check_login.sh脚本,可以监控Oracle数据库的登录情况:

#!/bin/bash# Set variables
LOG_DIR=/var/log/oracle
CHECK_DATE=$(date +%Y%m%d)
CHECK_TIME=$(date +%H:%M:%S)# Check for successful logins in the last hour
LOGIN_COUNT=$(grep -c "Successful login:" $LOG_DIR/listener.log | grep "$CHECK_DATE $CHECK_TIME" -C 60)
if [[ "$LOGIN_COUNT" -gt 0 ]]; thenecho "There were $LOGIN_COUNT successful logins in the last hour."
fi# Check for failed logins in the last hour
FAILED_COUNT=$(grep -c "Failed login:" $LOG_DIR/listener.log | grep "$CHECK_DATE $CHECK_TIME" -C 60)
if [[ "$FAILED_COUNT" -gt 0 ]]; thenecho "There were $FAILED_COUNT failed logins in the last hour."
fi# Check for locked accounts
LOCKED_ACCOUNTS=$($ORACLE_HOME/bin/sqlplus -S / as sysdba <<EOF
set heading off feedback off verify off
SELECT username FROM dba_users WHERE account_status = 'LOCKED';
EOF
)
if [[ -n "$LOCKED_ACCOUNTS" ]]; thenecho "The following database accounts are locked:"echo "$LOCKED_ACCOUNTS"
fi

该脚本通过搜索数据库监听器日志文件来检查成功和失败的登录次数,并在必要时输出相应的消息。它还查询数据库中的所有用户账户状态,以查找已锁定的账户。

请注意,此脚本只是一个示例,并且您可能需要根据您的具体需求进行修改和自定义。特别是对于登录时限、账户锁定的阈值等,需要根据实际情况来设置相应的参数。

5。写一个check_fund.sh异常退款

#!/bin/bash# Define variables for connecting to the database
DB_USER="username"
DB_PASSWORD="password"
DB_NAME="database_name"# Define variables for sending email notifications
EMAIL_FROM="sender@example.com"
EMAIL_TO="recipient@example.com"
EMAIL_SUBJECT="Alert: Abnormal refunds detected!"# Connect to the database and execute SQL query
refund_count=$(sqlplus -S ${DB_USER}/${DB_PASSWORD}@${DB_NAME} <<EOF
set feedback off;
set pagesize 0;
select count(*) from refunds where status='abnormal';
exit;
EOF
)# Check if refund count is greater than zero
if [ $refund_count -gt 0 ]
then# If refunds are abnormal, log the issue and send an email notificationecho "$(date '+%Y-%m-%d %H:%M:%S') - Abnormal refunds detected: $refund_count refunds" >> /var/log/check_fund.logecho "Please investigate and take appropriate action immediately." | mail -s "$EMAIL_SUBJECT" -r "$EMAIL_FROM" "$EMAIL_TO"
fi

此脚本连接到Oracle数据库并执行SQL查询,以检查是否存在“异常”状态的退款。如果退款数量大于零,则会在日志文件中记录问题,并发送电子邮件通知给指定收件人。请注意,您需要根据自己的环境和要求修改脚本中的变量和语句。

6.check_trade_status.sh脚本,可以监控交易状态的变化。

#!/bin/bash# Define variables for connecting to the database
DB_USER="username"
DB_PASSWORD="password"
DB_NAME="database_name"# Define variables for sending email notifications
EMAIL_FROM="sender@example.com"
EMAIL_TO="recipient@example.com"
EMAIL_SUBJECT="Alert: Trade status changed!"# Connect to the database and execute SQL query
trade_status=$(sqlplus -S ${DB_USER}/${DB_PASSWORD}@${DB_NAME} <<EOF
set feedback off;
set pagesize 0;
select status from trades where id='$1';
exit;
EOF
)# Check if trade status has changed
if [ "$trade_status" != "$2" ]
then# If trade status has changed, log the issue and send an email notificationecho "$(date '+%Y-%m-%d %H:%M:%S') - Trade status changed: trade id=$1, old status=$2, new status=$trade_status" >> /var/log/check_trade_status.logecho "Please investigate and take appropriate action immediately." | mail -s "$EMAIL_SUBJECT" -r "$EMAIL_FROM" "$EMAIL_TO"
fi

此脚本连接到Oracle数据库并执行SQL查询,以检查指定交易的当前状态。如果交易状态发生了变化,则会在日志文件中记录问题,并发送电子邮件通知给指定收件人。请注意,您需要根据自己的环境和要求修改脚本中的变量和语句。 

7. auto_immemory.sh 自动缓存每月初生成的新的分区

#!/bin/bash# Define variables for connecting to the database
DB_USER="username"
DB_PASSWORD="password"
DB_NAME="database_name"# Define variables for the partitioned table and index
TABLE_NAME="my_table"
INDEX_NAME="my_index"
PARTITION_PREFIX="PART"
PARTITION_EXPR="TO_DATE('2022-01-01','YYYY-MM-DD')"# Get current month and year
CURRENT_MONTH=$(date +%m)
CURRENT_YEAR=$(date +%Y)# Get name of partition to be cached
PARTITION_NAME="$PARTITION_PREFIX$CURRENT_YEAR$CURRENT_MONTH"# Check if partition exists and is not already cached in the In-Memory column store
partition_count=$(sqlplus -S ${DB_USER}/${DB_PASSWORD}@${DB_NAME} <<EOF
set feedback off;
set pagesize 0;
select count(*) from user_tab_partitions where table_name='$TABLE_NAME' and partition_name='$PARTITION_NAME' and inmemory_size=0;
exit;
EOF
)# If partition exists and is not already in-memory, cache it
if [ $partition_count -eq 1 ]
thensqlplus -S ${DB_USER}/${DB_PASSWORD}@${DB_NAME} <<EOFalter table $TABLE_NAME move partition $PARTITION_NAME compress for query low;alter table $TABLE_NAME inmemory priority high memcompress for query;alter index $INDEX_NAME rebuild partition $PARTITION_NAME nologging online compress;exit;
EOFecho "$(date '+%Y-%m-%d %H:%M:%S') - Partition $PARTITION_NAME cached in-memory." >> /var/log/auto_immemory.log
fi

此脚本连接到Oracle数据库并执行SQL查询,以检查每个月开始时是否生成了新的分区,并确定该分区是否已经被缓存到In-Memory列存储器中。如果分区存在且尚未缓存,则会将其移动到In-Memory列存储器中。请注意,您需要根据自己的环境和要求修改脚本中的变量和语句。

8.诊断所有共用通道数据 check_channel.sh脚本,用于诊断所有共用通道数据:

#!/bin/bash# Define variables for connecting to the database
DB_USER="username"
DB_PASSWORD="password"
DB_NAME="database_name"# Define variables for sending email notifications
EMAIL_FROM="sender@example.com"
EMAIL_TO="recipient@example.com"
EMAIL_SUBJECT="Alert: Shared channel issue detected!"# Connect to the database and execute SQL query
channel_count=$(sqlplus -S ${DB_USER}/${DB_PASSWORD}@${DB_NAME} <<EOF
set feedback off;
set pagesize 0;
select count(*) from v\$shared_server where status='INACTIVE';
exit;
EOF
)# Check if any shared channels are inactive
if [ $channel_count -gt 0 ]
then# If shared channels are inactive, log the issue and send an email notificationecho "$(date '+%Y-%m-%d %H:%M:%S') - Shared channel issue detected: $channel_count inactive channels" >> /var/log/check_channel.logecho "Please investigate and take appropriate action immediately." | mail -s "$EMAIL_SUBJECT" -r "$EMAIL_FROM" "$EMAIL_TO"
fi

此脚本连接到Oracle数据库并执行SQL查询,以检查所有共享通道的状态。如果任何共享通道处于“INACTIVE”状态,则会在日志文件中记录问题,并发送电子邮件通知给指定收件人。请注意,您需要根据自己的环境和要求修改脚本中的变量和语句。

9. 检查DG同步情况,check_dg.sh

#!/bin/bash# Define variables for connecting to the primary database
PRIMARY_DB_USER="primary_username"
PRIMARY_DB_PASSWORD="primary_password"
PRIMARY_DB_NAME="primary_database"# Define variables for connecting to the standby database
STANDBY_DB_USER="standby_username"
STANDBY_DB_PASSWORD="standby_password"
STANDBY_DB_NAME="standby_database"# Define variables for sending email notifications
EMAIL_FROM="sender@example.com"
EMAIL_TO="recipient@example.com"
EMAIL_SUBJECT="Alert: Data Guard synchronization issue detected!"# Connect to the primary and standby databases and execute SQL queries
primary_seq=$(sqlplus -S ${PRIMARY_DB_USER}/${PRIMARY_DB_PASSWORD}@${PRIMARY_DB_NAME} <<EOF
set feedback off;
set pagesize 0;
select max(sequence#) from v\$archived_log where applied='YES';
exit;
EOF
)standby_seq=$(sqlplus -S ${STANDBY_DB_USER}/${STANDBY_DB_PASSWORD}@${STANDBY_DB_NAME} <<EOF
set feedback off;
set pagesize 0;
select max(sequence#) from v\$archived_log where applied='YES';
exit;
EOF
)# Check if primary and standby databases are out of sync
if [ $primary_seq -ne $standby_seq ]
then# If databases are out of sync, log the issue and send an email notificationecho "$(date '+%Y-%m-%d %H:%M:%S') - Data Guard synchronization issue detected: primary sequence=$primary_seq, standby sequence=$standby_seq" >> /var/log/check_dg.logecho "Please investigate and take appropriate action immediately." | mail -s "$EMAIL_SUBJECT" -r "$EMAIL_FROM" "$EMAIL_TO"
fi

此脚本连接到主数据库和备库,并执行SQL查询以检查归档日志的序列号。如果主和备不同步,则会在日志文件中记录问题,并发送电子邮件通知给指定收件人。请注意,您需要根据自己的环境和要求修改脚本中的变量和语句。

10.监控OGG进程 check_ogg_proc.sh

#!/bin/bash# Define variables for the OGG process to monitor
OGG_PROCESS="my_ogg_process"# Define variables for sending email notifications
EMAIL_FROM="sender@example.com"
EMAIL_TO="recipient@example.com"
EMAIL_SUBJECT="Alert: OGG process issue detected!"# Check if the OGG process is running
if ps ax | grep -v grep | grep $OGG_PROCESS > /dev/null
thenecho "$(date '+%Y-%m-%d %H:%M:%S') - OGG process is running." >> /var/log/check_ogg_proc.log
else# If the OGG process is not running, log the issue and send an email notificationecho "$(date '+%Y-%m-%d %H:%M:%S') - OGG process is not running." >> /var/log/check_ogg_proc.logecho "Please investigate and take appropriate action immediately." | mail -s "$EMAIL_SUBJECT" -r "$EMAIL_FROM" "$EMAIL_TO"
fi

此脚本通过检查进程列表来确定OGG进程是否正在运行。如果进程未运行,则会在日志文件中记录问题,并发送电子邮件通知给指定收件人。请注意,您需要根据自己的环境和要求修改脚本中的变量和语句。

11.监控结算报表执行 check_sett_report.sh

#!/bin/bash# Define variables for connecting to the database
DB_USER="username"
DB_PASSWORD="password"
DB_NAME="database_name"# Define variables for sending email notifications
EMAIL_FROM="sender@example.com"
EMAIL_TO="recipient@example.com"
EMAIL_SUBJECT="Alert: Settlement report issue detected!"# Connect to the database and execute SQL query
report_count=$(sqlplus -S ${DB_USER}/${DB_PASSWORD}@${DB_NAME} <<EOF
set feedback off;
set pagesize 0;
select count(*) from settlement_reports where status='processing';
exit;
EOF
)# Check if any settlement reports are still processing
if [ $report_count -gt 0 ]
then# If reports are still processing, log the issue and send an email notificationecho "$(date '+%Y-%m-%d %H:%M:%S') - Settlement report issue detected: $report_count reports still processing" >> /var/log/check_sett_report.logecho "Please investigate and take appropriate action immediately." | mail -s "$EMAIL_SUBJECT" -r "$EMAIL_FROM" "$EMAIL_TO"
fi

12.监控最近两条汇率获取异常情况 check_unnormal_rate.sh

#!/bin/bash# Define variables for connecting to the database
DB_USER="username"
DB_PASSWORD="password"
DB_NAME="database_name"# Define variables for sending email notifications
EMAIL_FROM="sender@example.com"
EMAIL_TO="recipient@example.com"
EMAIL_SUBJECT="Alert: Unusual exchange rate issue detected!"# Connect to the database and execute SQL query
rate_count=$(sqlplus -S ${DB_USER}/${DB_PASSWORD}@${DB_NAME} <<EOF
set feedback off;
set pagesize 0;
select count(*) from exchange_rates where status='unusual' and rownum <= 2 order by date desc;
exit;
EOF
)# Check if there are any unusual exchange rates in the last two records
if [ $rate_count -gt 0 ]
then# If there are unusual exchange rates, log the issue and send an email notificationecho "$(date '+%Y-%m-%d %H:%M:%S') - Unusual exchange rate issue detected: $rate_count unusual rates" >> /var/log/check_unnormal_rate.logecho "Please investigate and take appropriate action immediately." | mail -s "$EMAIL_SUBJECT" -r "$EMAIL_FROM" "$EMAIL_TO"
fi

13.auto_tbsp_invalid.sh 监控表空间使用情况,检查失效对象并自动重编译,监控风控时间,监控银行时间,检查数据库对象数量,检查归档空间。

#!/bin/bash# Define variables for connecting to the database
DB_USER="username"
DB_PASSWORD="password"
DB_NAME="database_name"# Define variables for sending email notifications
EMAIL_FROM="sender@example.com"
EMAIL_TO="recipient@example.com"
EMAIL_SUBJECT="Alert: Oracle database issue detected!"# Define threshold values for tablespace usage (percentage)
TABLESPACE_THRESHOLD=85# Check tablespace usage and send an email notification if any tablespaces exceed the threshold
tablespace_count=$(sqlplus -S ${DB_USER}/${DB_PASSWORD}@${DB_NAME} <<EOF
set feedback off;
set pagesize 0;
select count(*) from dba_data_files where round((bytes-free_space)/bytes*100) >= $TABLESPACE_THRESHOLD;
exit;
EOF
)if [ $tablespace_count -gt 0 ]
then# If any tablespaces exceed the threshold, log the issue and send an email notificationecho "$(date '+%Y-%m-%d %H:%M:%S') - Tablespaces exceeding usage threshold detected." >> /var/log/auto_tbsp_invalid.logecho "Please investigate and take appropriate action immediately." | mail -s "$EMAIL_SUBJECT" -r "$EMAIL_FROM" "$EMAIL_TO"
fi# Check for invalid objects and recompile them automatically
invalid_count=$(sqlplus -S ${DB_USER}/${DB_PASSWORD}@${DB_NAME} <<EOF
set feedback off;
set pagesize 0;
select count(*) from user_objects where status='INVALID';
exit;
EOF
)if [ $invalid_count -gt 0 ]
thensqlplus -S ${DB_USER}/${DB_PASSWORD}@${DB_NAME} <<EOFalter system disable restricted session;alter system set "_system_trig_enabled" = false scope=both;@$ORACLE_HOME/rdbms/admin/utlrp.sql;alter system reset "_system_trig_enabled" scope=both;alter system enable restricted session;exit;
EOFecho "$(date '+%Y-%m-%d %H:%M:%S') - Invalid objects detected and recompiled." >> /var/log/auto_tbsp_invalid.log
fi# Check if current time falls within defined risk window
current_time=$(date +%H%M)
risk_start_time=900
risk_end_time=1800if [ $current_time -ge $risk_start_time ] && [ $current_time -le $risk_end_time ]
thenecho "$(date '+%Y-%m-%d %H:%M:%S') - Current time is within the defined risk window." >> /var/log/auto_tbsp_invalid.log
else# If current time is outside of the defined risk window, log the issue and send an email notificationecho "$(date '+%Y-%m-%d %H:%M:%S') - Current time is outside of the defined risk window." >> /var/log/auto_tbsp_invalid.logecho "Please investigate and take appropriate action immediately." | mail -s "$EMAIL_SUBJECT" -r "$EMAIL_FROM" "$EMAIL_TO"
fi# Check if current time falls within defined bank hours
bank_start_time=800
bank_end_time=1700if [ $current_time -ge $bank_start_time ] && [ $current_time -le $bank_end_time ]
thenecho "$(date '+%Y-%m-%d %H:%M:%S') - Current time is within bank hours." >> /var/log/auto_tbsp_invalid.log
else# If current time is outside of bank hours, log the issue and send an email notificationecho "$(date '+%Y-%m-%d %H:%M:%S') - Current time is outside of bank hours." >> /var/log/auto_tbsp_invalid.logecho "Please investigate and take appropriate action immediately." | mail -s "$EMAIL_SUBJECT" -r "$EMAIL_FROM" "$EMAIL_TO"
fi# Check the number of database objects and send an email notification if it exceeds a specified limit
object_limit=100000object_count=$(sqlplus -S ${DB_USER}/${DB_PASSWORD}@${DB_NAME} <<EOF
set feedback off;
set pagesize 0;
select count(*) from dba_objects;
exit;
EOF
)if [ $object_count -ge $object_limit ]
then# If the object count exceeds the limit, log the issue and send an email notificationecho "$(date '+%Y-%-%d %H:%M:%S') - Number of database objects exceeds limit: $object_count" >> /var/log/auto_tbsp_invalid.log
echo "Please investigate and take appropriate action immediately." | mail -s "$EMAIL_SUBJECT" -r "$EMAIL_FROM" "$EMAIL_TO"
fi# Check the available space in the archive log destination and send an email notification if it is running lowarchive_space=$(sqlplus -S ${DB_USER}/${DB_PASSWORD}@${DB_NAME} <<EOF
set feedback off;
set pagesize 0;
select round((total_mb-free_mb)/total_mb*100) from v$recovery_file_dest;
exit;
EOF
)if [ $archive_space -ge $TABLESPACE_THRESHOLD ]
then
# If the archive log destination space is running low, log the issue and send an email notification
echo "$(date '+%Y-%m-%d %H:%M:%S') - Low space in archive log destination detected: $archive_space%" >> /var/log/auto_tbsp_invalid.log
echo "Please investigate and take appropriate action immediately." | mail -s "$EMAIL_SUBJECT" -r "$EMAIL_FROM" "$EMAIL_TO"
fi

此脚本监控数据库表空间使用情况,检查失效对象并自动重编译,监控风险时间和银行时间,检查数据库对象数量,以及检查归档空间。如果任何问题超过阈值,则在日志文件中记录问题,并发送电子邮件通知给指定收件人。请注意,您需要根据自己的环境和要求修改脚本中的变量和语句。

14.监控数据库错误日志 check_hkoral_err.sh

#!/bin/bash# Define variables for accessing the alert log
ORACLE_SID="sid"
ALERT_LOG="/u01/app/oracle/diag/rdbms/${ORACLE_SID}/${ORACLE_SID}/trace/alert_${ORACLE_SID}.log"# Define variables for sending email notifications
EMAIL_FROM="sender@example.com"
EMAIL_TO="recipient@example.com"
EMAIL_SUBJECT="Alert: Oracle database error detected!"# Check the alert log for ORA- errors
error_count=$(grep -ic "ORA-" $ALERT_LOG)if [ $error_count -gt 0 ]
then# If any errors are found, log the issue and send an email notificationecho "$(date '+%Y-%m-%d %H:%M:%S') - Oracle database error detected: $error_count errors" >> /var/log/check_hkoral_err.logecho "Please investigate and take appropriate action immediately." | mail -s "$EMAIL_SUBJECT" -r "$EMAIL_FROM" "$EMAIL_TO"
fi

此脚本检查Oracle数据库的警报日志,以查找任何ORA-错误。如果发现错误,则会在日志文件中记录问题,并发送电子邮件通知给指定收件人。请注意,您需要根据自己的环境和要求修改脚本中的变量和语句.


15.监控汇率波动情况 check_rate.sh

#!/bin/bash# Define variables for connecting to the database
DB_USER="username"
DB_PASSWORD="password"
DB_NAME="database_name"# Define variables for sending email notifications
EMAIL_FROM="sender@example.com"
EMAIL_TO="recipient@example.com"
EMAIL_SUBJECT="Alert: Exchange rate fluctuation detected!"# Define threshold values for exchange rate fluctuations (percentage)
RATE_THRESHOLD=5# Connect to the database and execute SQL query
rate_fluct_count=$(sqlplus -S ${DB_USER}/${DB_PASSWORD}@${DB_NAME} <<EOF
set feedback off;
set pagesize 0;
select count(*) from exchange_rates where abs((rate-prev_rate)/prev_rate*100) >= $RATE_THRESHOLD;
exit;
EOF
)# Check if any exchange rates have fluctuated beyond the threshold
if [ $rate_fluct_count -gt 0 ]
then# If exchange rates have fluctuated beyond the threshold, log the issue and send an email notificationecho "$(date '+%Y-%m-%d %H:%M:%S') - Exchange rate fluctuation detected: $rate_fluct_count rates" >> /var/log/check_rate.logecho "Please investigate and take appropriate action immediately." | mail -s "$EMAIL_SUBJECT" -r "$EMAIL_FROM" "$EMAIL_TO"
fi

此脚本连接到Oracle数据库并执行SQL查询,以检查是否有超过阈值的汇率波动。如果发现波动,则会在日志文件中记录问题,并发送电子邮件通知给指定收件人。请注意,您需要根据自己的环境和要求修改脚本中的变量和语句。 

16.监控异常银行订单 check_trade.sh

#!/bin/bash# Define variables for connecting to the database and accessing the alert log
DB_USER="username"
DB_PASSWORD="password"
DB_NAME="database_name"
ORACLE_SID="sid"
ALERT_LOG="/u01/app/oracle/diag/rdbms/${ORACLE_SID}/${ORACLE_SID}/trace/alert_${ORACLE_SID}.log"# Define variables for sending email notifications
EMAIL_FROM="sender@example.com"
EMAIL_TO="recipient@example.com"
EMAIL_SUBJECT="Alert: Abnormal bank trades detected!"# Check for abnormal bank trades in the database
trade_count=$(sqlplus -S ${DB_USER}/${DB_PASSWORD}@${DB_NAME} <<EOF
set feedback off;
set pagesize 0;
select count(*) from bank_trades where status='abnormal' and rownum <= 10 order by trade_date desc;
exit;
EOF
)if [ $trade_count -gt 0 ]
then# If abnormal bank trades are found, log the issue and send an email notificationecho "$(date '+%Y-%m-%d %H:%M:%S') - Abnormal bank trades detected: $trade_count trades" >> /var/log/check_trade.logecho "Please investigate and take appropriate action immediately." | mail -s "$EMAIL_SUBJECT" -r "$EMAIL_FROM" "$EMAIL_TO"
fi# Check the alert log for any errors related to bank trades
error_count=$(grep -ic "bank trade error" $ALERT_LOG)if [ $error_count -gt 0 ]
then# If errors related to bank trades are found, log the issue and send an email notificationecho "$(date '+%Y-%m-%d %H:%M:%S') - Bank trade errors detected: $error_count errors" >> /var/log/check_trade.logecho "Please investigate and take appropriate action immediately." | mail -s "$EMAIL_SUBJECT" -r "$EMAIL_FROM" "$EMAIL_TO"
fi

此脚本检查数据库中是否有异常银行订单,并检查警报日志中是否有与银行订单相关的错误。如果发现问题,则会在日志文件中记录问题,并发送电子邮件通知给指定收件人。请注意,您需要根据自己的环境和要求修改脚本中的变量和语句。

17.删除14天之前的归档日志 del_archive.sh

#!/bin/bash# Define variables for accessing the archive log destination and setting retention period (days)
ARCHIVE_DEST="/u01/app/oracle/fast_recovery_area/${ORACLE_SID}/archivelog"
RETENTION_DAYS=14# Calculate the date for retention
RETENTION_DATE=$(date +%Y%m%d --date="${RETENTION_DAYS} days ago")# Delete archive logs older than the retention date
find $ARCHIVE_DEST -name "*.arc" -o -name "*.log" | grep -E ".*[0-9]{8}.*" | while read FILE
doFILE_DATE=$(echo $FILE | grep -oE "[0-9]{8}")if [ $FILE_DATE -lt $RETENTION_DATE ]thenrm $FILEecho "$(date '+%Y-%m-%d %H:%M:%S') - Archive log deleted: $FILE" >> /var/log/del_archive.logfi
done

此脚本遍历归档日志目录以查找14天之前的归档日志,并将其删除。请注意,您需要根据自己的环境和要求修改脚本中的变量和语句。在使用此脚本之前,请确保理解脚本的作用并进行适当的测试。

相关文章:

Shell自动化管理 for ORACLE DBA

1.自动收集每天早上9点到晚上8点之间的AWR报告。 auto_awr.sh #!/bin/bash# Set variables ORACLE_HOME/u01/app/oracle/product/12.1.0/dbhome_1 ORACLE_SIDorcl AWR_DIR/home/oracle/AWR# Set date format for file naming DATE$(date %Y%m%d%H%M%S)# Check current time - …...

Unity学习日记13(画布相关)

目录 创建画布 对画布的目标图片进行射线检测 拉锚点 UI文本框使用 按钮 按钮导航 按钮触发事件 输入框 实现单选框 下拉菜单 多选框选项加图片 创建画布 渲染模式 第一个&#xff0c;保持画布在最前方&#xff0c;画布内的内容显示优先级最高。 第二个&#xff0c;…...

初阶C语言:冒泡排序

冒泡排序是一种简单的排序算法&#xff0c;它重复地走访过要排序的数列&#xff0c;一次比较两个元素&#xff0c;如果他们的顺序错误就把他们交换过来。走访数列的工作是重复地进行直到没有再需要交换&#xff0c;也就是说该数列已经排序完成。1.冒泡排序关于冒泡排序我们在讲…...

带头双向循环链表

在前面我们学习了单链表&#xff0c;发现单链表还是有一些不够方便&#xff0c;比如我们要尾插&#xff0c;需要遍历一遍然后找到它的尾&#xff0c;这样时间复炸度就为O(N),现在我们引入双向带头链表就很方便了&#xff0c;我们先看看它的结构。通过观察&#xff0c;我们发现一…...

C#中的DataGridView中添加按钮并操作数据

背景&#xff1a;最近在项目中有需求需要在DataGridView中添加“删除”、“修改”按钮&#xff0c;用来对数据的操作以及显示。 在DataGridView中显示需要的按钮 首先在DataGridView中添加需要的列&#xff0c;此列是用来存放按钮的。 然后在代码中“画”按钮。 if (e.Column…...

WEB安全 PHP基础

WEB安全 PHP基础 PHP简述 PHP&#xff08;全称&#xff1a;PHP&#xff1a;Hypertext Preprocessor&#xff0c;即"PHP&#xff1a;超文本预处理器"&#xff09;是一种通用开源脚本语言。 在一个php文件中可以包括以下内容&#xff1a;  PHP 文件可包含文本、HTML、…...

基础篇:07-Nacos注册中心

1.Nacos安装部署 1.1 下载安装 nacos官网提供了安装部署教程&#xff0c;其下载链接指向github官网&#xff0c;选择合适版本即可。如访问受阻可直接使用以下最新稳定版压缩包&#xff1a;&#x1f4ce;nacos-server-2.1.0.zip&#xff0c;后续我们也可能会更改为其他版本做更…...

端口镜像讲解

目录 端口类型 镜像方向 观察端口位置 端口镜像实现方式 流镜像 Vlan镜像 MAC镜像 配置端口镜像 配置本地观察端口 配置远程流镜像&#xff08;基于流镜像&#xff09; 端口镜像是指将经过指定端口的报文复制一份到另一个指定端口&#xff0c;便于业务监控和故障定位…...

图形视图框架QGraphicsScene(场景,概念)

QGraphicsScene 该类充当 QGraphicsItems 的容器。它与 QGraphicsView 一起使用&#xff0c;用于在 2D 表面上可视化图形项目&#xff0c;例如线条、矩形、文本甚至自定义项目。 QGraphicsScene具有的功能&#xff1a; 提供用管理大量数据项的高速接口传播事件到每一个图形项…...

ChatGPT 拓展资料: 强化学习-SARSA算法

强化学习是一种机器学习技术,它关注的是在特定环境中,如何最大化一个智能体(agent)的累积奖励(reward)。强化学习算法会根据当前状态和环境的反馈来选择下一个动作,不断地进行试错,从而优化智能体的行为。 SARSA是一种基于强化学习的算法,它可以用于解决马尔可夫决策…...

SpringJDBC异常抽象

前言spring会将所有的常见数据库的操作异常抽象转换成他自己的异常&#xff0c;这些异常的基类是DataAccessException。DataAccessException是RuntimeException的子类&#xff08;运行时异常&#xff09;,是一个无须检测的异常,不要求代码去处理这类异常SQLErrorCodeSQLExcepti…...

我在字节的这两年

前言 作为脉脉和前端技术社区的活跃分子&#xff0c;我比较幸运的有了诸多面试机会并最终一路升级打怪如愿来到了这里。正式入职时间为2021年1月4日&#xff0c;也就是元旦后的第一个工作日。对于这一天&#xff0c;我印象深刻。踩着2020年的尾巴接到offer,属实是过了一个快乐…...

Button(按钮)与ImageButton(图像按钮)

今天给大家介绍的Android基本控件中的两个按钮控件,Button普通按钮和ImageButton图像按钮; 其实ImageButton和Button的用法基本类似,至于与图片相关的则和后面ImageView相同,所以本节只对Button进行讲解,另外Button是TextView的子类,所以TextView上很多属性也可以应用到B…...

Chrome插件开发-右键菜单开启页面编辑

开发一个执行js脚本改变页面DOM的Chrome插件&#xff0c;manifest_version版本为3。 Chrome插件基本知识 Chrome插件通常由以下几部分组成&#xff1a; manifest.json 该文件为必须项&#xff0c;其它文件都是可选的。该文件相当于插件的meta信息&#xff0c;包含manifest版…...

指针进阶(上)

内容小复习&#x1f431;&#xff1a; 字符指针:存放字符的数组 char arr1[10]; 整型数组:存放整型的数组 int arr2[5]; 指针数组:存放的是指针的数组 存放字符指针的数组(字符指针数组) char* arr3[5]; 存放整型指针的数组(整型指针数组) int* arr[6]; 下面进入学习了哦~&…...

Python每日一练(20230318)

目录 1. 排序链表 ★★ 2. 最长连续序列 ★★ 3. 扰乱字符串 ★★★ &#x1f31f; 每日一练刷题专栏 &#x1f31f; Golang每日一练 专栏 Python每日一练 专栏 C/C每日一练 专栏 Java每日一练 专栏 1. 排序链表 给你链表的头结点 head &#xff0c;请将其按 升序 …...

多层多输入的CNN-LSTM时间序列回归预测(卷积神经网络-长短期记忆网络)——附代码

目录 摘要&#xff1a; 卷积神经网络(CNN)的介绍&#xff1a; 长短期记忆网络&#xff08;LSTM&#xff09;的介绍&#xff1a; CNN-LSTM&#xff1a; Matlab代码运行结果&#xff1a; 本文Matlab代码数据分享&#xff1a; 摘要&#xff1a; 本文使用CNN-LSTM混合神经网…...

mybatis中获取参数的两种方式:${}和#{}

目录 1.#{} 2.${} 3.总结 1.#{} 本质是占位符赋值 示例及执行结果&#xff1a; 结论&#xff1a;通过执行结果可以看到&#xff0c;首先对sql进行了预编译处理&#xff0c;然后再传入参数&#xff0c;有效的避免了sql注入的问题&#xff0c;并且传参方式也比较简单&#xf…...

复制带随机指针的复杂链表

目录一、题目题目链接二、题目分析三、解题思路四、解题步骤4.1 复制结点并链接到对应原节点的后面4.2 处理复制的结点的随机指针random4.3 分离复制的链表结点和原链表结点并重新链接成为链表五、参考代码六、总结一、题目题目链接 ​​​​ ​ 题目链接&#xff1a;https://…...

【基于协同过滤算法的推荐系统项目实战-2】了解协同过滤推荐系统

本文目录1、推荐系统的关键元素1.1 数据1.2 算法1.3 业务领域1.4 展示信息2、推荐算法的主要分类2.1 基于关联规则的推荐算法基于Apriori的算法基于FP-Growth的算法2.2 基于内容的推荐算法2.3 基于协同过滤的推荐算法3、推荐系统常见的问题1、冷启动2、数据稀疏3、不断变化的用…...

线程安全(重点)

文章目录一.线程安全的概念1.1 线程安全的概念1.2 线程不安全的原因1.3 解决线程不安全二.synchronized-monitor lock(监视器锁)2.1 synchronized的特性(1)互斥(2)刷新内存(3)可重入2.2 synchronied使用方法1.直接修饰普通方法:2.修饰静态方法:3.修饰代码块:三.死锁3.1死锁的情…...

软件测试面试找工作你必须知道的面试技巧(帮助超过100人成功通过面试)

目录 问题一&#xff1a;“请你自我介绍一下” 问题二&#xff1a;“谈谈你的家庭情况” 问题三&#xff1a;“你有什么业余爱好?” 问题四&#xff1a;“你最崇拜谁?” 问题五&#xff1a;“你的座右铭是什么?” 问题六&#xff1a;“谈谈你的缺点” 问题七&#xff…...

Python快速入门:类、文件操作、正则表达式

类、文件操作、正则表达式1. 类2. 文件操作3. 正则表达式1. 类 类是用来描述具有相同的属性和方法的集合&#xff0c;定义了该集合中每个对象共有的属性和方法&#xff0c;对象是类的实例&#xff0c;可以调用类的方法。 定义类时&#xff0c;如有父类&#xff0c;则写在类名…...

java-day01

程序就是有序指令的集合 cmd执行java程序&#xff0c;javac Test.java&#xff0c;java Test java技术平台&#xff1a; javaSE标准版&#xff0c;javaEE企业版&#xff0c;javaME小型版 java语言面向对象的&#xff08;oop&#xff09;&#xff0c;java跨平台性的&#xff08;…...

玩转 Node.js 集群

一、介绍 Node 在 v0.8 时直接引入了 cluster 模块&#xff0c;用以解决多核 CPU 的利用率问题&#xff0c;同时也提供了较完善的 API&#xff0c;用以处理进程的健壮性问题。 cluster 模块调用 fork 方法来创建子进程&#xff0c;该方法与 child_process 中的 fork 是同一个…...

Day909.MySQL 不同的自增 id 达到上限以后的行为 -MySQL实战

MySQL 不同的自增 id 达到上限以后的行为 Hi&#xff0c;我是阿昌&#xff0c;今天学习记录的是关于MySQL 不同的自增 id 达到上限以后的行为的内容。 MySQL 里有很多自增的 id&#xff0c;每个自增 id 都是定义了初始值&#xff0c;然后不停地往上加步长。 虽然自然数是没有…...

JVM学习.01 内存模型

1、前言对于C、C程序员来说&#xff0c;在内存管理领域&#xff0c;他们拥有对象的“所有权”。从对象建立到内存分配&#xff0c;不仅需要照顾到对象的生&#xff0c;还得照顾到对象的消亡。背负着每个对象生命开始到结束的维护和管理责任。对于JAVA程序来说&#xff0c;因为J…...

R+VIC模型应用及未来气候变化模型预测

RVIC模型融合实践技术应用及未来气候变化模型预测在气候变化问题日益严重的今天&#xff0c;水文模型在防洪规划&#xff0c;未来预测等方面发挥着不可替代的重要作用。目前&#xff0c;无论是工程实践或是科学研究中都存在很多著名的水文模型如SWAT/HSPF/HEC-HMS等。虽然&…...

搞懂vue 的 render 函数, 并使用

render函数是什么 简单的说&#xff0c;在vue中我们使用模板HTML语法组建页面的&#xff0c;使用render函数我们可以用js语言来构建DOM 因为vue是虚拟DOM&#xff0c;所以在拿到template模板时也要转译成VNode(虚拟节点)的函数&#xff0c;而用render函数构建DOM&#xff0c;vu…...

【Linux】GDB的安装与使用

安装安装gdb的具体步骤如下&#xff1a;1、查看当前gdb安装情况rpm -qa | grep gdb如果有&#xff0c;则可以先删除&#xff1a;rpm -e --nodeps 文件名如果没有&#xff0c;则进行下一步。2、下载gdb源码包或者直接apt安装。apt命令安装&#xff1a;sudo apt install gdb源码包…...