import subprocess
from datetime import datetime, timedelta, timezone
import requests
from datetime import datetime
from apscheduler.schedulers.blocking import BlockingScheduler
scheduler = BlockingScheduler()
# 发送通知请求
def send_msg_to_gotify(title, msg):
url = "http://152.136.153.72:8385/message"
params = {"token": "AI.53prwavAZsoC"}
current_time = datetime.now()
# 表单数据
data = {
"title": title,
"message": msg,
"priority": "0"
}
try:
response = requests.post(
url,
params=params,
data=data
)
print("Response Body:", response.text)
except requests.exceptions.RequestException as e:
print("请求失败:", e)
def check_ssl_certificate_expiration(web_site, out_date):
# 执行 openssl 命令获取证书信息
try:
result = subprocess.run(
["openssl", "x509", "-in", "fullchain.pem", "-noout", "-dates"],
capture_output=True,
text=True,
check=True,
cwd=f"C:\\Certbot\\live\\{web_site}"
)
except subprocess.CalledProcessError as e:
print("执行 openssl 命令失败:", e)
return
# 解析输出,提取 notAfter 日期
output = result.stdout
not_after_str = None
for line in output.splitlines():
if line.startswith("notAfter="):
not_after_str = line.split("=", 1)[1].strip()
break
if not not_after_str:
print("未找到 notAfter 信息")
return
# 解析日期字符串为 datetime 对象(使用 GMT 时间)
try:
date_format = "%b %d %H:%M:%S %Y GMT"
not_after_date = datetime.strptime(not_after_str, date_format).replace(tzinfo=timezone.utc)
except ValueError as e:
print("日期解析失败:", e)
return
# 获取当前 UTC 时间
current_date = datetime.now(timezone.utc)
# 计算时间差
delta = not_after_date - current_date
# 判断是否在 15 天内且未过期
if 0 <= delta.days <= out_date:
print(f"⚠️ SSL 证书({web_site})将在 {delta.days} 天后过期,请及时续期!")
send_msg_to_gotify('SSL即将过期', f'SSL 证书({web_site})将在 {delta.days} 天后过期,请及时更新并重启nginx服务')
elif delta.days < 0:
print(f"❌ SSL 证书({web_site})已过期!")
send_msg_to_gotify('SSL即将过期', f'SSL 证书({web_site})已过期,请及时更新并重启nginx服务')
else:
print(f"✅ SSL 证书({web_site})有效期超过 {out_date} 天,无需处理。")
# 执行检查
@scheduler.scheduled_job('cron', hour=8, minute=30, misfire_grace_time=3600)
def tick():
check_ssl_certificate_expiration('cx.sdasinfo.org.cn', 15)
try:
scheduler.start()
print('定时任务成功执行')
except Exception as e:
scheduler.shutdown()
print('定时任务执行失败')
finally:
exit()
]]>命令 | 说明 |
---|---|
git init | 初始化仓库 |
git clone | 拷贝一份远程仓库,也就是下载一个项目。 |
命令 | 说明 |
---|---|
git add | 添加文件到暂存区 |
git status | 查看仓库当前的状态,显示有变更的文件。 |
git diff | 比较文件的不同,即暂存区和工作区的差异。 |
git difftool | 使用外部差异工具查看和比较文件的更改。 |
git range-diff | 比较两个提交范围之间的差异。 |
git commit | 提交暂存区到本地仓库。 |
git reset | 回退版本。 |
git rm | 将文件从暂存区和工作区中删除。 |
git mv | 移动或重命名工作区文件。 |
git notes | 添加注释。 |
git checkout | 分支切换。 |
git switch (Git 2.23 版本引入) | 更清晰地切换分支。 |
git restore (Git 2.23 版本引入) | 恢复或撤销文件的更改。 |
git show | 显示 Git 对象的详细信息。 |
命令 | 说明 |
---|---|
git remote | 远程仓库操作 |
git fetch | 从远程获取代码库 |
git pull | 下载远程代码并合并 |
git push | 上传远程代码并合并 |
git submodule | 管理包含其他 Git 仓库的项目 |
设置
git config --global https.proxy 代理地址
git config --global http.proxy 代理地址
查看
git config --global --get https.proxy
git config --global --get https.proxy
查询的时候没有打印任何东西证明没有设置代理
取消
git config --global --unset http.proxy
git config --global --unset https.proxy
命令 | 说明 |
---|---|
npm install | 安装新的包(全局范围内安装一个包,可以使用-g 或--global 标志) |
npm uninstall | 从项目中移除依赖包。它会从package.json 文件中删除指定的包,并卸载它 |
npm update | 用于更新项目中的依赖包。它可以更新所有依赖包,也可以指定更新某个特定的包 |
npm cache | 管理npm的缓存(npm cache clean --force) |
npm config | 设置或查看npm的配置选项(查看配置:npm config list) |
npm config set proxy http://127.0.0.1:10808
npm confit set https-proxy http://127.0.0.1:10809
取消代理
npm config delete proxy
npm config delete https-proxy
设置源(官方)
npm config set registry https://registry.npmjs.org/
设置源(淘宝)
npm config set registry https://registry.npmmirror.com/
查看源
npm get registry
删除源
npm config delete registry
命令 | 操作 | 参数 | 标签 | |
---|---|---|---|---|
yarn add | 添加依赖包 | 包名 | --dev/-D | |
yarn bin | 显示yarn安装目录 | 无 | 无 | |
yarn cache | 显示缓存 | 列出缓存包:ls ,打出缓存目录路径:dir ,清除缓存:clean | 无 | |
yarn check | 检查包 | |||
yarn clean | 清理不需要的依赖文件 | |||
yarn config | 配置 | 设置:set <key> <value> , 删除:delete , 列出:list | [-g \ | --global] |
yarn generate-lock-entry | 生成锁定文件 | 无 | 无 | |
yarn global | 全局安装依赖包 | yarn global <add/bin/ls/remove/upgrade> [--prefix] | --prefix 包路径前缀 | |
yarn info | 显示依赖包的信息 | 包名 | --json:json格式显示结果 | |
yarn init | 互动式创建/更新package.json文件 | 无 | --yes/-y:以默认值生成package.json文件 | |
yarn install | 安装所有依赖包 | --flat:只安装一个版本;--force:强制重新下载安装;--har:输出安装时网络性能日志;--no-lockfile:不生成yarn.lock文件;--production:生产模式安装(不安装devDependencies中的依赖) | ||
yarn list | 列出已安装依赖包 | --depth=0:列表深度,从0开始 | ||
yarn outdated | 检查过时的依赖包 | 包名 | ||
yarn pack | 给包的依赖打包 | --filename | ||
yarn publish | 将包发布到npm | --tag:版本标签;--access:公开(public)还是限制的(restricted) | ||
yarn remove | 卸载包,更新package.json和yarn.lock | 包名 | ||
yarn upgrade | 升级依赖包 | |||
yarn version | 管理当前项目的版本号 | --new-version :直接记录版本号;--no-git-tag-version:不生成git标签 |
设置源(淘宝)
yarn config set registry https://registry.npmmirror.com/
设置源(官方)
yarn config set registry https://registry.yarnpkg.com
删除源
yarn config delete registry
查看代理
yarn config list
设置
yarn config set proxy http://127.0.0.1:10809
yarn config set https-proxy http://127.0.0.1:10808
取消
yarn config delete proxy
yarn config delete https-proxy
全局安装:npm install -g rimraf
进行删除:rimraf node_modules
npm run lint -- --fix
或者yarn lint --fix
因为涉及到服务启动,所以都需要管理员权限运行。
mysql
开关脚本:
@echo off
for /f "skip=3 tokens=4" %%i in ('sc query mysql') do set "zt=%%i" &goto :next
:next
if /i "%zt%"=="RUNNING" (
echo ========================================
echo 该服务mysql现在处于 开启状态
echo %date:~0,4%年%date:~5,2%月%date:~8,2%日%time:~0,2%时%time:~3,2%分
echo ========================================
) else (
echo ========================================
echo 该服务mysql现在处于 停止状态
echo %date:~0,4%年%date:~5,2%月%date:~8,2%日%time:~0,2%时%time:~3,2%分
echo ========================================
)
choice /c:YN /m "开启[Y]关闭[N] MySQL 服务"
if errorlevel 2 goto two
if errorlevel 1 goto one
:one a
echo 正在开启 MySQL 服务...
net start mysql
echo MySQL 服务开启成功
choice /c:YN /m "是[Y]否[N]要开启SQLyong"
if errorlevel 2 exit
if errorlevel 1 start "" "D:\Program Files\Webyog SQLyog Ultimate\SQLyog.exe"
>nul
:two
echo 正在关闭 MySQL 服务...
net stop mysql
echo MySQL 服务关闭成功
taskkill /f /im "SQLyog.exe"
echo 请按任意键退出...
pause>nul
exit
VM
开关脚本:
@echo off
for /f "skip=3 tokens=4" %%i in ('sc query "VMAuthdService"') do set "zt=%%i" &goto :next
:next
if /i "%zt%"=="RUNNING" (
echo 服务VMware Authorization Service正在运行
) else (
echo 服务VMware Authorization Service已停止
)
for /f "skip=3 tokens=4" %%i in ('sc query "VMnetDHCP"') do set "zt=%%i" &goto :next
:next
if /i "%zt%"=="RUNNING" (
echo 服务VMware DHCP Service正在运行
) else (
echo 服务VMware DHCP Service已停止
)
for /f "skip=3 tokens=4" %%i in ('sc query "VMware NAT Service"') do set "zt=%%i" &goto :next
:next
if /i "%zt%"=="RUNNING" (
echo 服务VMware NAT Service正在运行
) else (
echo 服务VMware NAT Service已停止
)
for /f "skip=3 tokens=4" %%i in ('sc query "VMUSBArbService"') do set "zt=%%i" &goto :next
:next
if /i "%zt%"=="RUNNING" (
echo 服务VMware USB Arbitration Service正在运行
) else (
echo 服务VMware USB Arbitration Service已停止
)
for /f "skip=3 tokens=4" %%i in ('sc query "VMwareHostd"') do set "zt=%%i" &goto :next
:next
if /i "%zt%"=="RUNNING" (
echo 服务VMware Workstation Server正在运行
) else (
echo 服务VMware Workstation Server已停止
)
choice /c:12 /m "启动/停止VM虚拟机服务及网络连接[1启动,2停止]"
if errorlevel 2 goto two
if errorlevel 1 goto one
:one
echo 正在启用VM各项服务,请耐心等待......
net start "VMnetDHCP"
net start "VMware NAT Service"
net start "VMUSBArbService"
net start "VMAuthdService"
::net start "VMwareHostd"
echo 正在启用网络连接...
netsh interface set interface "VMware Network Adapter VMnet1" enable
netsh interface set interface "VMware Network Adapter VMnet8" enable
echo 网络连接VMware Network Adapter VMnet1、VMware Network Adapter VMnet8启动成功
choice /c:12 /m " 是否启动VMware Workstations...[1是,2否]"
if errorlevel 2 exit
if errorlevel 1 start "" "D:\Program Files (x86)\VMware\VMware Workstation\vmware.exe"
>nul
:two
echo 正在禁用VM各项服务,请耐心等待......
::net stop "VMwareHostd"
net stop "VMnetDHCP"
net stop "VMware NAT Service"
net stop "VMUSBArbService"
net stop "VMAuthdService"
echo 正在禁用网络连接...
netsh interface set interface "VMware Network Adapter VMnet1" disable
netsh interface set interface "VMware Network Adapter VMnet8" disable
echo 网络连接VMware Network Adapter VMnet1、VMware Network Adapter VMnet8禁用成功
taskkill /f /im "vmware.exe"
echo 按任意键退出...
pause>nul
exit
刚才再写操作日志的时候,因为涉及到时间的缘故,偶然间学了一手