I use git init --bare example.git
create git repo in my localhost, user is git.
and I use root to git clone, run every minute with crontab, the command is:
*/1 * * * * git --git-dir=/opt/xxx/.git --work-tree=/opt/xxx pull 1>>/tmp/git.log 2>&1
the output log is:
Permission denied (publickey,keyboard-interactive).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
Then I try:
*/1 * * * * cd /opt/xxx/ && git pull 1>>/tmp/git2.log 2>&1
But the output is the same.
If I run in command line, all is ok:
Already up-to-date.
I don't know why can't run with crontab?
Agent-based authentication requires that the SSH process has access to the $SSH_AUTH_SOCK environment variable, but that variable won't be set when run via the crontab. You may want to consider switching to a passphrase-less keypair or an anonymous authentication method.
If that's not an option you could write the contents of the $SSH_AUTH_SOCK environment variable (possibly also $SSH_AGENT_PID) to a local file that you can read from your crontab-run script and set the variables so that they're available to SSH.
One last option is to drop the crontab entry and manually start up a shell script that runs as a daemon and periodically performs the pull.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments