用于Oracle数据库巡检的示例脚本:
#!/bin/bash# 设置数据库连接信息
DB_USER="your_db_username"
DB_PASSWORD="your_db_password"
DB_HOST="your_db_host"
DB_PORT="your_db_port"
DB_SID="your_db_sid"
OUTPUT_FILE="/path/to/output.log"# 巡检开始时间
start_time=$(date +"%Y-%m-%d %H:%M:%S")
echo "Start Time:" $start_time > $OUTPUT_FILE
echo "" >> $OUTPUT_FILE# 检查数据库连接
echo "Database Connection:" >> $OUTPUT_FILE
sqlplus -S $DB_USER/$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_SID << EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SELECT 'Connected to Oracle ' || version FROM dual;
EOF
echo "" >> $OUTPUT_FILE# 检查数据库大小
echo "Database Size:" >> $OUTPUT_FILE
sqlplus -S $DB_USER/$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_SID << EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SELECT ROUND(SUM(bytes)/1024/1024, 2) AS "Total Size(MB)" FROM dba_data_files;