Use shell to check for errors in logs and send emails if any errors occur.
Source: Internet
Author: User
#! /Bin/bash # Initialize the environment variable source. bash_profile # The inherent date format f_name in the log name = 'date + % Y % m % d' # the path and name of the log log_file =/backup/db/rman/log/rman $ f_name-0401.logecho $ log_file # count the number of log files # line_num = 'WC-l $ log_file | #! /Bin/bash
# Initializing environment variables
Source. bash_profile
# Inherent date format in log name
F_name = 'date + % Y % m % d'
# Log path and name
Log_file =/backup/db/rman/log/rman $ f_name-0401.log
Echo $ log_file
# Counting the number of log files
# Line_num = 'WC-l $ log_file | awk '{print $1 }''
# Echo $ line_num
# If the log file does not exist, send an email directly. otherwise, check whether the file contains the erro and Erro keywords. If yes, send an email.
If [! -E $ log_file]
Then
Echo "send mail"
Echo "file not found $ log_file" | mutt-s "BI database rman backup error" -- 393741056@qq.com
Else
Erro_num = 'cat $ log_file | grep 'erro '| wc-L'
Erro_num = 'cat $ log_file | grep 'erro '| wc-L'
If [$ erro_num-gt 0-o $ Erro_num-gt 0]
Then
Echo "send mail"
Echo "check file $ log_file" | mutt-s "BI database rman backup error" -- 393741056@qq.com
Fi
Fi
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service