定时脚本自动自动将文件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
相关推荐
春日见2 小时前
如何创建一个PR
运维·开发语言·windows·git·docker·容器
stevenzqzq21 小时前
git 常用操作
大数据·git
Curvatureflight1 天前
Git工作流最佳实践:从混乱到优雅
git
wu~9701 天前
GitHub永不遗忘,使用git push -f来覆盖的提交依旧保留
git·github
Vermouth_001 天前
git clone的时候提示access denied
git
qq_437657271 天前
清楚本地的git并重新登录
git
jiang_changsheng1 天前
工作流agent汇总分析 2
java·人工智能·git·python·机器学习·github·语音识别
顶点多余1 天前
版本控制器-git
linux·git
夔曦1 天前
Git工程日常下拉/上传完整流程(自用)
git
岱宗夫up1 天前
GitHub Desktop如何设置中文?这不是个简单问题
git·github