系列文章git介绍-常用操作(一)✓git实战——linux定时监控github更新状态(二)✓本文主要内容如何查看github本地仓库和远程仓库同步linux服务器定时监控github更新状态并自动发送邮件到qq邮箱配置文件需要centos:7.6.1810mailx:12.5sendmail:8.14.7监控yourgithubstatus查看本地仓库的同步状态。只需使用gitstatus检查结果。结果包括uncached、unsubmitted、submittedclean查看远程仓库的同步状态。gitremoteshoworigin可以查看远程仓库和本地仓库的状态:包括快进、最新、过时。定时监控远程仓库同步shell脚本#!/bin/shexportLANG=en_US.UTF-8source/etc/profilepaths=$PWDdirs=("01_pics""00_blogs")log_path=$paths/git_log.txtmail_address="***@foxmail.com"echo"beginat:`date`">$log_pathforiin${dirs[*]};docur_path="$paths/$i"cd$cur_pathecho$cur_pathecho-e"\n*******$i*************">>$log_pathgit状态>>$log_pathecho"----远程状态--------">>$log_pathgit远程显示来源>>$log_path#foriin`ls`#do#echo$i#doneoneflag=1forlinein`cat$log_path`doifecho$line|egrep-i"FAST-FORWARDABLE|Obsolete|FAST-FORWARDABLE|OUT-OF-DATE"thenflag=0breakfidoneif(($flag==0))thenmail-s"warning!!!github已更新,相信请查看附件"-a$log_path$mail_address<$log_pathelseecho"github很干净"|mail-s"github很干净"$mail_addressFi配置定时调度,每小时运行一次0****sh/root/workfile/gitspace/github_status_check.sh>/dev/null2>&1配置和发送邮件步骤安装相应插件yuminstallmailx编辑配置文件vim/etc/mail.rcsetfrom=***@qq.comsetsmtp=smtp.qq.comsetsmtp-auth-user=***@qq.comsetsmtp-auth-password=qq邮箱授权码设置smtp-auth=登录授权码获取方式进入qq邮箱→设置→账户→选择开通服务:POP3/SMTP服务→会提示发送邮件到指定号码发送邮件testecho'Thisistestmail'|mail-s'test'***@foxmail.com
