小编run*_*ace的帖子

通过脚本使用 ssh 身份验证自动化 git pull(非交互式)

我有一堆运行 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,但这就是我设法让它工作的方式。

ssh git

5
推荐指数
1
解决办法
4634
查看次数

After=multi-user.target 和其他不在 systemd 服务中工作的

我有一个工作的服务,只有在运行之后才工作,因为它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)

systemd services

4
推荐指数
1
解决办法
9938
查看次数

将 bash 函数的结果与 bash 命令一起使用

我创建了一个名为的 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)

pipe shell-script

0
推荐指数
1
解决办法
32
查看次数

标签 统计

git ×1

pipe ×1

services ×1

shell-script ×1

ssh ×1

systemd ×1