定时脚本自动自动将文件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
相关推荐
程序员阿鹏1 小时前
Git的安装和配置(idea中配置Git)
java·开发语言·ide·git·intellij-idea·idea
belldeep14 小时前
如何阅读、学习 Git 核心源代码 ?
git·学习·源代码
我不是秃头sheep14 小时前
Git安装教程及常用命令
git
sduwcgg1 天前
git经验
git
麻雀无能为力1 天前
git的使用
git
算法歌者1 天前
Visual Studio 项目 .gitignore 文件指南
git·visual studio
江边垂钓者1 天前
git cherry-pick和git stash命令详解
git
Lw老王要学习1 天前
Linux架构篇、第五章git2.49.0部署与使用
linux·运维·git·云计算·it
爱学习的张哥1 天前
专栏项目框架介绍
git·fpga开发·udp·ddr·gt收发器
Aric_Jones1 天前
lua入门语法,包含安装,注释,变量,循环等
java·开发语言·git·elasticsearch·junit·lua