提交修改

This commit is contained in:
halliday 2023-12-14 10:06:13 +08:00
parent 63448854e8
commit 02e3d542b6
5 changed files with 0 additions and 206 deletions

BIN
Document/使用方法.docx Normal file

Binary file not shown.

View File

@ -1,90 +0,0 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import smtplib
import subprocess
import shutil
import os
from email.mime.text import MIMEText
from email.header import Header
from email.mime.multipart import MIMEMultipart
from datetime import datetime
"""
执行备份集检查将检查结果发送邮件
使用方法
1.先手动确认backupCheckTool.jar运行无问题
2.将本脚本和backupCheckTool.jar放在同一个目录中
3.修改邮箱的收发件人地址
4.执行脚本
"""
#公共的
now=os.path.dirname(os.path.abspath(__file__))
week = str(datetime.now().isocalendar()[1])
file_path=os.path.join(now,"report.txt")
file_name_week="report" + week + ".txt"
file_week_path=os.path.join(now,file_name_week)
#检查工具
checktool=os.path.join(now,"backupCheckTool.jar")
if not os.path.exists(checktool):
assert False,u'backupCheckTool.jar not found,please check it!!'
def send_mail():
# 发件人
sender = 'mh@unamail.com'
# 接收邮件,可以发给多人
receivers = ['mh@unamail.com']
# 邮件主体
msg = MIMEMultipart()
# 正文
#文本内容太多了,不放了。
#with open(file_path, "r") as f: # 打开文本
# msgdata = f.read()
msgdata=""
message = "{0}周,备份集检测已完成,检测内容将附件\n{1}".format(
week, msgdata)
msg.attach(MIMEText(message, 'plain', _charset="utf-8"))
# 发送者
msg['From'] = Header(sender, 'utf-8')
# 接收者
msg['To'] = Header(receivers[0], 'utf-8')
# 主题
subject = '【长期任务】备份集检查-W{0}'.format(week)
msg['Subject'] = Header(subject, 'utf-8')
# 附件信息
att = MIMEText(open(file_week_path, 'rb').read(), 'base64', 'utf-8')
att["Content-Type"] = 'application/octet-stream'
att["Content-Disposition"] = 'attachment; filename="{}"'.format(
file_name_week)
msg.attach(att)
try:
smtpObj = smtplib.SMTP('10.10.110.102')
smtpObj.sendmail(sender, receivers, msg.as_string())
print("邮件发送成功")
except smtplib.SMTPException:
print("Error: 无法发送邮件")
def main():
#删除之前的文件
if os.path.exists(file_path):
os.remove(file_path)
#运行检查工具
commdline = ['java', '-jar', '-Dusername=unadba', '-Dpassword=1223Bc@2008', 'backupCheckTool.jar']
recode=subprocess.call(commdline)
#处理检查结果
shutil.copy2(file_path,file_week_path)
#发邮件
send_mail()
if __name__ == '__main__':
main()

View File

@ -1,30 +0,0 @@
#!/bin/bash
#set -x
PRG="$0"
while [ -h "$PRG" ]; do
ls=$(ls -ld "$PRG")
link=$(expr "$ls" : '.*-> \(.*\)$')
if expr "$link" : '.*/.*' >/dev/null; then
PRG="$link"
else
PRG=$(dirname "$PRG")/"$link"
fi
done
PRGDIR=$(dirname "$PRG")
#full path
cd $PRGDIR
ROOT_DIR=$(pwd)
cd - >/dev/null
# 加载Python3环境
if [ -f /opt/rh/rh-python38/enable ]; then
source /opt/rh/rh-python38/enable
fi
function check_sucessful
recode=`mysql -uunadba -p1223Bc@2008 unary -e 'select 1-(tb1.n1/tb2.n2) from ( (select sum(number) as n1 from ( select operdesc,count(*) as number from tbl_jobhistory where policyname="长期系统" and compid="bd22ea57feecb5a7f96e67035c204e02" group by operdesc) as tmp1 where tmp1.operdesc like "%失败%") as tb1 right JOIN (select count(*) as n2 from tbl_jobhistory where policyname="长期系统" and compid="bd22ea57feecb5a7f96e67035c204e02") tb2 on 1=1);' | tail -1`

View File

@ -1,45 +0,0 @@
@echo off
echo 开始获取本机信息,请稍等......
rem 代理的logs路径
set agentlog="D:\agent\ubackup\uagent\logs"
rem 定义输出的文件
for /f "tokens=*" %%i in ('powershell -c "Get-Date -UFormat %%V"') do (
set vars=%%i
)
set filename=C:\ComputerInfos_week_%vars%.txt
echo 本周是第:%vars%>>%filename%
SET CurrentTime=%date:~0,10% %time:~0,5%
echo 本次运行时间:%CurrentTime% >>%filename%
rem 查看内存使用情况
echo 1.内存使用情况:>>%filename%
wmic OS get FreePhysicalMemory| findstr /r /v "^$" | more >>%filename%
wmic ComputerSystem get TotalPhysicalMemory| findstr /r /v "^$" |more >>%filename%
rem 查看磁盘使用情况:
echo 2.磁盘使用情况:>>%filename%
wmic logicaldisk get caption,freespace,size| findstr /r /v "^$"|more >>%filename%
rem 查看CPU使用情况
echo 3.CPU使用率>>%filename%
wmic cpu get loadpercentage| findstr /r /v "^$"|more >>%filename%
rem 查看日志文件大小:
echo 4.日志文件路径:>>%filename%
dir %agentlog% >>%filename%
echo "===================%CurrentTime%已经获取系统信息================ " >>%filename%

View File

@ -1,41 +0,0 @@
#!/bin/bash
#set -x
#uagent路径地址
uagent_dir=/agent/ubackup/uagent/logs/
#创建存放的目录
report_dir="/opt/sys-info/"
mkdir -p $report_dir
IP=`hostname -I|awk '{print $1}'`
#按周创建文件,一周一个
week_number=`date +%V`
filename=${IP}-ComputerInfos-week-${week_number}.txt
file_path=$report_dir/$filename
#输出需要的信息
now=$(date +"%Y-%m-%d %H:%M:%S")
echo "-------------------------------------------" >> $file_path
echo "当前时间:$now" >> $file_path
echo "当前地址:$IP" >> $file_path
# CPU
echo "" >> $file_path
echo "内存信息:">> $file_path
free -h >> $file_path
# uagent_dir的日志大小
echo "" >> $file_path
echo "uagent日志大小">> $file_path
du -h $uagent_dir >> $file_path
# 磁盘空间使用情况
echo "" >> $file_path
echo "磁盘空间使用情况:">> $file_path
df -h >> $file_path
echo "" >> $file_path
echo "-------------------------------------------" >> $file_path