I’m using Logseq to take notes and I set up a repo on AWS CodeCommit to backup/sync the graph.
I wrote an sh script that syncs the graph folder: it pulls new commits, adds modified files to the stage area, commits with an empty message and then pushes the new commit.
I also use Healthchecks to automatically monitor this operation.
#!/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/$?
(Since I use Logseq on more than one PC I also added the hostname
to the head of the message to know which PC made the commit)
When running the script manually, i.e. from terminal, it works fine, but when it is executed by cron the message recorded from Healthchecks show the error
<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.
I really cannot figure out where the problem is.
Update #1
I updated the ssh key used, removing its passphrase as @phd suggested in the comment, but the problem persists.
The error massege has changed: before, the username
reported was my PC user name (e.g. myusername
), now it’s CodeCommit SSH key ID (e.g. WCCJLNFCGHYPDVU
)
Update #2
Found an old question (ssh-agent and crontab — is there a good way to get these to meet?), I tried adding SSH_AUTH_SOCK=/run/user/1000/keyring/ssh
directly in crontab and script files, then tried adding eval 'ssh-agent -s'
in script, none of the two solutions worked.
I even reloaded crontab after each attempt via /etc/init.d/cron reload
.
5