Deprecated: Creation of dynamic property Typecho\Widget\Request::$feed is deprecated in /www/wwwroot/blog.iletter.top/var/Widget/Archive.php on line 246
白荼日记 - bash
https://blog.iletter.top/index.php/tag/bash/
-
python每日检查网站ssl证书是否过期
https://blog.iletter.top/index.php/archives/402.html
2025-07-26T23:58:48+08:00
目的是检查网站是否过期,过期前几天进行通知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、npm、yarn常用设置和命令(查阅)
https://blog.iletter.top/index.php/archives/182.html
2024-10-09T00:01:00+08:00
git创建仓库命令命令说明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 代理设置设置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.proxyNPM常用命令命令说明npm install安装新的包(全局范围内安装一个包,可以使用-g或--global标志)npm uninstall从项目中移除依赖包。它会从package.json文件中删除指定的包,并卸载它npm update用于更新项目中的依赖包。它可以更新所有依赖包,也可以指定更新某个特定的包npm cache管理npm的缓存(npm cache clean --force)npm config设置或查看npm的配置选项(查看配置:npm config list)NPM设置代理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 registryyarn常用命令命令操作参数标签yarn add添加依赖包包名--dev/-Dyarn 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设置代理设置源(淘宝)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-proxyrimraf快速删除node_modules文件夹全局安装:npm install -g rimraf进行删除:rimraf node_modulesESLint 自动修复npm run lint -- --fix 或者yarn lint --fix
-
bat启动mysql和vm
https://blog.iletter.top/index.php/archives/49.html
2023-02-19T23:48:00+08:00
受限于电脑比较垃圾,23年了,还用着五年前的电脑。再加之软件更新迭代快,对性能的要求也渐渐地有了要求。自己也开始对系统开始做一些优化,禁用一些不需要的服务。必要时再开启。昨晚上半夜学了点bat的操作方式,写了俩脚本耍耍。因为涉及到服务启动,所以都需要管理员权限运行。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 刚才再写操作日志的时候,因为涉及到时间的缘故,偶然间学了一手