定时脚本自动自动将文件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 天前
Ubuntu中 git上传自己的项目和二次上传一般流程
git·github
Patrick_Wilson2 天前
Squash Merge 的血缘陷阱:为什么删掉的代码又活了过来
前端·git·程序员
沉浸学习的匿名网友3 天前
什么是 .gitignore?为什么每个 Git 项目几乎都离不开它?
前端·git
深海鱼在掘金4 天前
Git 完全指南 —— 第3章:理解工作区、暂存区、版本库三个核心
git
江华森4 天前
Git 基础筑基:从原理到团队协作的全栈实战
git
JakeJiang4 天前
Git 必备命令指南:从日常高频到项目开发实战
git
叫我少年5 天前
Windows 中安装 git
git
深海鱼在掘金10 天前
Git 完全指南 —— 第1章:Git 概览与版本控制演进
git
noravinsc11 天前
关于Git Flow
git
蜜獾云11 天前
在Git中配置用户名和密码
git