【发布时间】:2021-12-31 07:16:24
【问题描述】:
当我们关闭 PC 时,我正在尝试运行 git auto push 的脚本。但是我的脚本和服务文件只执行了提交命令,之后网络就断了。所以,它不执行推送命令。
如何在网络不通之前完成脚本的执行?
我的服务文件:
[Unit]
Description=It will auto commit and push using auto-commit-push-script
DefaultDependencies=no
Wants=network-online.target
After=network-online.target
Before=halt.target poweroff.target shutdown.target
[Service]
Type=oneshot
# RemainAfterExit=true
ExecStart=/bin/true
ExecStop=/home/user/git-auto-commit/git_auto_commit.sh
TimeoutStopSec=60
[Install]
WantedBy=halt.target poweroff.target shutdown.target
我的脚本:
#!/bin/bash
cd /home/user/Basics
username="xyz"
password="xyz"
git add .
git commit -m "Auto-Commit On PC shut down"
git push https://$username:$password@github.com/username/Basics.git --all
谁能帮我解决这个问题?
【问题讨论】:
-
这实际上与 Git 没有任何关系 - 任何 网络操作都会有相同的问题,例如 scp、rsync、
tar cf - dir | ssh backupsite savestuff等等。不过,VonC 的回答很好。