Ubuntu下Cron执行Git同步脚本遇AWS CodeCommit权限问题
Cron执行Git同步脚本时AWS CodeCommit权限拒绝
我用Logseq记录笔记,搭建AWS CodeCommit仓库用于备份同步笔记图谱,编写了Shell脚本实现拉取新提交、暂存修改、空消息提交并推送的同步流程,同时用Healthchecks.io监控操作。脚本内容如下:
#!/bin/sh # Sync local directory to S3 bucket notifying healthchecks.io checkid=$1 dir=$2 # start check curl -fsS -m 10 --retry 5 https://hc-ping.com/$checkid/start # backup # git pull->commit->push redirecting stderr to stdout and storing all output to variable m m=$( hostname \ && git -C $dir pull 2>&1 \ && git -C $dir add . \ && git -C $dir commit -a --allow-empty-message -m '' \ && git -C $dir push 2>&1) # stop check passing exit status curl -fsS -m 10 --retry 5 --data-raw "$m" https://hc-ping.com/$checkid/$?
(因在多台PC使用Logseq,故在消息头部添加hostname以区分提交来源)
手动运行脚本一切正常,但通过Cron执行时,Healthchecks记录如下错误:
<user>@git-codecommit.<aws-region>.amazonaws.com: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
我无法定位问题根源,已做以下尝试:
- 更新1:移除SSH密钥的密码短语,问题依旧,错误信息变更:原显示PC用户名,现显示CodeCommit SSH密钥ID
- 更新2:尝试在Crontab和脚本中设置
SSH_AUTH_SOCK=/run/user/1000/keyring/ssh,或在脚本中添加eval 'ssh-agent -s',每次尝试后均重载Crontab,但均无效
内容的提问来源于stack exchange,提问作者fudo
相关产品推荐
相关产品推荐

