写脚本
绝对路径
环境注意
写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
local_ip = os.popen(“ifconfig”).read()#.splitlines()[2].split(" ")[-1]
current_time = datetime.datetime.now().strftime(“%Y-%m-%d %H:%M:%S”)
with open(“/home/pi/gittest/ipset/sshpi10/1.txt”, “w”) as f:
f.write(f"{local_ip}\n{current_time}\n")
crontab -e
定制任务