定时脚本自动自动将文件push到git

写脚本

绝对路径

环境注意

写python,bash脚本执行调用 py程序

定制crontab -e

日志要指定输入文件中

项目地址

https://gitee.com/stdev_1/sshpi10/

bash脚本

#!/bin/bash

设置要监控的仓库路径

#path=~/github/

#watch_dir="/home/pi/gittest/ipset/sshpi10"

python3 /home/pi/gittest/ipset/sshpi10/readip.py

cd /home/pi/gittest/ipset/sshpi10

git pull

git add .

git commit -m 'ip'

git push -u origin master

python脚本执行的主体功能,

要将ip和时间戳,写入本地文件,文件推送 git

import datetime

import os

获取本地 IP 地址

local_ip = os.popen("ifconfig").read()#.splitlines()2.split(" ")-1

获取当前时间

current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

将本地 IP 地址和当前时间写入到 1.txt 文件

with open("/home/pi/gittest/ipset/sshpi10/1.txt", "w") as f:

f.write(f"{local_ip}\n{current_time}\n")

crontab -e

定制任务

          • /bin/bash /home/pi/gittest/ipset/sshpi10/apush.sh >> /home/pi/bashset.log 2>&1
相关推荐
leoZ2311 天前
Git 集成实战完全指南(三):自动化 Commit 与 PR
大数据·git·elasticsearch
国服第二切图仔1 天前
002-Claude Code 项目解读:入口与启动流程
linux·git·ubuntu
天空'之城1 天前
VS Code Git 工作树:告别频繁切分支,实现多分支并行开发实战方案
git·vscode·版本控制·嵌入式开发·开发效率·worktree·多分支管理
程序员爱德华1 天前
VSCode git/gerrit解冲突
git·vscode·gerrit
leoZ2312 天前
Git 集成实战完全指南(二):智能分支管理
大数据·git·elasticsearch
qq_452396232 天前
第六篇:《GitLab CI 进阶:多环境部署与环境变量管理》
git·ci/cd·gitlab
有想法的py工程师2 天前
GPG 密钥迁移指南:多私钥备份、批量导入与自动信任
git·github
浮江雾2 天前
Flutter第五节------Flutter开发环境配置与项目创建指南
开发语言·前端·git·学习·flutter·入门·函数
aramae2 天前
C++11:现代C++的里程碑
c语言·开发语言·c++·windows·git·后端
BerryS3N2 天前
VS Code Git 工作树:解锁多分支并行开发新体验
大数据·git·elasticsearch