当前位置: 首页 > news >正文

定时脚本自动自动将文件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
http://www.lryc.cn/news/155236.html

相关文章:

  • 025: vue父子组件中传递方法控制:$emit,$refs,$parent,$children
  • 使用js搭建简易的WebRTC实现视频直播
  • LeetCode 2707. Extra Characters in a String【动态规划,记忆化搜索,Trie】1735
  • 设计模式行为型-模板模式
  • 9.3.tensorRT高级(4)封装系列-自动驾驶案例项目self-driving-车道线检测
  • django.core.exceptions.AppRegistryNotReady: Apps aren‘t loaded yet.
  • 【C#】C#调用进程打开一个exe程序
  • 宝塔面板定时监控和重启MySQL数据库(计划任务)
  • Beats:安装及配置 Metricbeat (二)- 8.x
  • Redis之哨兵模式解读
  • 题目:2644.找出可整除性得分最大的整数
  • 报错:axios 发送的接口请求 404
  • 三年前端还不会配置Nginx?刷完这篇就够了
  • blender 场景灯光基础设置
  • 如何查看 SQLyog 中数据库连接信息中的密码
  • 【SpringSecurity】八、集成图片验证码
  • 【本地代码问题】启动程序,报错:java.lang.IllegalArgumentException: No selectors
  • 手写RPC框架--4.服务注册
  • oracle 解锁表
  • 使用Dbeaver连接GaussDB
  • WSL使用技巧 / 虚拟机对比
  • vuex_cart案例
  • Linux系统的安装
  • 微服务设计和高并发实践
  • 2023年高教社杯数学建模思路 - 案例:粒子群算法
  • Tomcat 集群介绍
  • Windows右键添加用 IDEA 打开
  • Golang 中return和defer执行先后顺序
  • 业务数据模拟/采集
  • qt day 5