#!/bin/bash
# ------------------------------------------
# Filename: cutalert.sh
# Revision: 1.1
# Date: 2023/02/17
# Author:xu
# Description:截取当天警告日志文件
# ------------------------------------------
# Copyright: 2023 xu
# License: GPL
LANG='en_US.UTF-8'
#edate_today 英文日期
edate_today=`date|awk '{print $1,$2,$3}'`
#pri_ipadd 网卡bond1 ip地址
pri_ipadd=`ifconfig bond1|grep "inet "|awk '{print $2}'|cut -d: -f2`
echo $edate_today
LANG='zh_CN.UTF-8'
# cdate_today 中午日期
cdate_today=`date +'%Y-%m-%d'`
echo $cdate_today
# oraclesid 数组存放实例名
oraclesid=(`ps -ef |grep smon|grep oracle|awk '{print $8}'|awk -F_ '{print $3}'`)
for pwdsid in ${oraclesid[@]}
do
path_pwd="/u01/app/oracle/diag/rdbms/"${pwdsid:0:${#pwdsid}-1}"/"$pwdsid"/trace/"
echo $path_pwd
cd $path_pwd
mkdir ./alertlog 2>/dev/null
# 截取当天日志并保存到当日文件中
sed -n -e "/^$edate_today/,/GG/p" alert_${pwdsid}.log >./alertlog/alert_${pwdsid}_${cdate_today}.log
ssh oracle@ip 'mkdir -p /alertlog/'${pri_ipadd}'/'${cdate_today}
scp ./alertlog/alert_${pwdsid}_${cdate_today}.log oracle@ip2:/alertlog/${pri_ipadd}/${cdate_today}/
done