提交脚本

This commit is contained in:
halliday 2023-12-14 10:01:52 +08:00
parent bdbb78fe94
commit 8ab0d08440
8 changed files with 386 additions and 0 deletions

View File

@ -0,0 +1,80 @@
#encoding=utf-8
import csv
from faker import Faker
"""
生成尽可能真实的假数据
使用方法
1.安装依赖包
pip install faker
2.执行脚本
python faker_demo.py
3.当前目录查看生成的数据
"""
#保存为csv文件
def save_data_csv(file_name):
#获取数据
datas = faker_data()
#保存
with open(file_name,'w+',encoding='utf-8',newline='') as file_csv:
writer = csv.writer(file_csv, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL)
writer.writerows(datas)
#生成数据
def faker_data():
#指定数据的国家地区
f = Faker('zh-CN')
#定义一个列表,用来存放所有数据
datas = []
#标题
title = ["uuid","id","name","mobile","ssn","sex","email","job","address","actime_time"]
#title2 = ["唯一标识","编号","姓名","手机号","身份证号","性别","邮箱","职业","家庭地址","获取时间"]
#添加标题到列表中
datas.append(title)
#datas.append(title2)
#开始按照标题的顺序生成200条数据
for i in range(0,100):
#定义一个列表,用来存一行数据
data = []
#uuid
data.append(f.uuid4())
#编号001不足3位的左边用0来补齐
data.append(str(i+1).rjust(3,'0'))
#姓名
data.append(f.name())
#手机号
data.append(f.phone_number())
#身份证
ssn = f.ssn()
data.append(ssn)
#性别根据身份证的第17位来判断
ssn_sex = int(ssn[16:17])
#0102
if ssn_sex % 2:
sex = "01"
else:
sex = "02"
data.append(sex)
#邮箱
data.append(f.email())
#职业
data.append(f.job())
#地址,让其更加复合中国的地址
address = f.address()[:-9] + str(f.pyint(min_value=0, max_value=999))+ ""
data.append(address)
#获取时间近3年的
actime_time = f.date_time_between(start_date="-3y", end_date="now")
data.append(actime_time)
#将这一行数据添加到datas中
datas.append(data)
#返回所有的数据
return datas
if __name__ == '__main__':
#文件名
file_name = 'test.csv'
save_data_csv(file_name)

View File

@ -0,0 +1,61 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import smtplib
import os
from email.mime.text import MIMEText
from email.header import Header
from email.mime.multipart import MIMEMultipart
from datetime import datetime
"""
将作业成功率的结果发邮件
"""
#公共的
now=os.path.dirname(os.path.abspath(__file__))
file_path=os.path.join(now,"check_report.txt")
week = str(datetime.now().isocalendar()[1])
def send_mail():
# 发件人
sender = 'mh@unamail.com'
# 接收邮件,可以发给多人
receivers = ['mh@unamail.com','zry@unamail.com','ypy@unamail.com','zxw@unamail.com']
# 邮件主体
msg = MIMEMultipart()
# 正文取文本中的内容
with open(file_path, "r") as f:
msgdata = f.read()
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: 无法发送邮件")
if __name__ == '__main__':
send_mail()

View File

@ -0,0 +1,64 @@
#!/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
echo "" >$ROOT_DIR/check_report.txt
# 查询某个策略的成功率
function check_sucessful(){
# 代理信息和策略名
comname=$1
compid=$2
policyname=$3
#查询
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='${policyname}' and compid='${compid}' group by operdesc) as tmp1 where tmp1.operdesc like '%失败%') as tb1 right JOIN (select count(*) as n2 from tbl_jobhistory where policyname='${policyname}' and compid='${compid}') tb2 on 1=1);" | tail -1`
#输出结果
echo -e "${comname}" >>$ROOT_DIR/check_report.txt
echo -e "\t ${policyname} 的作业成功率为: ${recode}" >>$ROOT_DIR/check_report.txt
echo -e "\n-----------\n" >>$ROOT_DIR/check_report.txt
}
# 需要检查的代理
# mh
check_sucessful "6.9长期mh_MySQL定时备份_13.167" "811da1a9258bb690d58aaef5aa958027" "长期任务-mysql物理多通道"
check_sucessful "6.9长期mh_OraclePhysical定时备份_29.41" "effbff8590c4c69a33151fa4d4fff2e1" "长期Oracle多通道"
check_sucessful "6.9长期mh_系统定时备份_29.33" "bd22ea57feecb5a7f96e67035c204e02" "长期系统"
# ypy
check_sucessful "6.9长期MySQLCDM_linux_29.48_ypy" "50061b4e4f80fa802067209eb18a232f" "长期"
check_sucessful "6.9长期OracleCDM备份_linux_29.40_ypy" "46117564f229b9b7f407b21aa5d7fa1c" "长期"
check_sucessful "6.9长期分区_WIN_29.47_ypy" "d9f991a83017a2b4ad9161044f5fca8f" "长期"
#zry
check_sucessful "6.9长期定时文件29.49_zry" "b1b4c1d1b276265ae78914f350e29f96" "多通道"
check_sucessful "6.9长期定时文件29.49_zry" "b1b4c1d1b276265ae78914f350e29f96" "普通"
check_sucessful "6.9长期副本文件CDM备份29.42_zry" "55037758a2f200826bff0061d6dbdb91" "文件CDM"
check_sucessful "6.9长期副本文件CDM备份29.42_zry" "55037758a2f200826bff0061d6dbdb91" "218"
echo "开始发送邮件"
#python $ROOT_DIR/SendCheckJobReport.py

View File

@ -0,0 +1,2 @@
用途:
检查指定的代理策略的成功率,并将结果发邮件

View File

@ -0,0 +1,45 @@
@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

@ -0,0 +1,41 @@
#!/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

View File

@ -0,0 +1,3 @@
获取机器的一些信息目前已经放弃使用了改为py来处理
https://gitea.kiki.kim/ha/check-system-info.git

View File

@ -0,0 +1,90 @@
#!/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()