我有一堆运行 Ubuntu 20.04 服务器的树莓派,我希望通过 Git 以非交互方式自动更新。
该脚本执行以下操作:
eval "$(ssh-agent -s)" ; ssh-add /home/michael/.ssh/terminal_github_deploy_key ; git -C /home/michael/terminal/src pull
Run Code Online (Sandbox Code Playgroud)
该脚本实际上是用 Python 编写的,但其作用与上面相同:
cmds = []
cmds.append('eval "$(ssh-agent -s)"')
cmds.append(f'ssh-add {HOME_DPATH}/.ssh/terminal_github_deploy_key')
cmds.append(f'git -C {CHECKOUT_DPATH} pull')
cmd = ' ; '.join(cmds)
subprocess.check_call(cmd, shell=True)
Run Code Online (Sandbox Code Playgroud)
除了引发此交互式警告之外,它工作正常:
The authenticity of host 'github.com (140.82.121.3)' can't be established.
ECDSA key fingerprint is SHA256:...
Are you sure you want to continue connecting (yes/no/[fingerprint])?
Run Code Online (Sandbox Code Playgroud)
根据研究,出于安全原因,它故意不接受管道(因此yes | ...不起作用)。我不确定是什么引发了警告,我猜测是 SSH,被 Git 调用,但不知道如何忽略它?我不必使用ssh-add,但这就是我设法让它工作的方式。
我有一个工作的服务,只有在运行之后才工作,因为它dhcpcd.service执行 github pull,并且除非 DHCP 启动,否则它无法解析主机。network.target早在 DHCP 服务完成之前就完成了。请注意,当服务应该运行时,用户michael将不会登录(它是服务器)。
问题是我无法让它运行得足够晚才能工作,而不诉诸一些超长的丑陋延迟来覆盖所有情况,例如
ExecStartPre=sleep 30
Run Code Online (Sandbox Code Playgroud)
这是服务(我尝试过的updatecontinue.service多种组合之一):After=
# man systemd.service
# man systemd.unit
#
# Debug with (will print errors at the bottom, time is in UTC!):
# -n50 to show 50 lines
# sudo systemctl status updatecontinue
#
# Or to get a plot (open with chrome so its searchable):
# systemd-analyze plot > ~/plot.svg
[Unit]
Description=Check if an update is halfway through, if yes, then …Run Code Online (Sandbox Code Playgroud) 我创建了一个名为的 bash 函数get:
get() {
$(fd -H | fzf)
}
Run Code Online (Sandbox Code Playgroud)
fd就像find,它将找到的所有文件通过管道传输到fzf模糊查找器中,这使我可以找到文件。
我希望能够使用get各种命令,例如echoor ls,但我无法“让它”工作(请原谅双关语),例如
# I am in home dir, and the result from get is 'Documents'
$ ls $(get)
Documents: command not found
$ ls `get`
Documents: command not found
$ echo get | ls
# Just performs ls on current dir not result from get
$ ls get
ls: cannot access 'get': No such file or directory …Run Code Online (Sandbox Code Playgroud)