Cron job Auto-Push to Git Issue

Kevin

I have a cron job setup to run a bash script to push to Git every night.

The cron job was setup as root, and I have set my git credentials via: git config credential.helper store as per: Git push: username, password, how to avoid? (second answer)

The code for the bash script is pretty simple

#!/bin/bash

# Nightly push to Bitbucket

# Set some variables
DAY=$(date +%F);

# Make sure we run as root
if [ "$(whoami)" != "root" ]; then
    echo "Only root can do this.";
    exit 1;
else
    # Make sure we are in the right directory
    cd /hosting;
    # Now add any changes
    git add .;
    # Now commit
    git commit -m "$DAY Nightly";
    git push all;
fi;

And runs without a hiccup so long as I log into the server and run it as root.

However, it does not run at the specified time.

Crontab -e is set with: 30 3 * * * back-to-git >/dev/null 2>&1

What can I do to get it to work?

cb0

First off, it's alway better to include the full path of your script inside the cron tab.

30 3 * * * /opt/btg/back-to-git >/dev/null 2>&1

Replace /opt/btg/back-to-git with the absolute path to your script. Then try to not throw away the output which my contain errors:

30 3 * * * /opt/btg/back-to-git &>/home/your_user/btg.log 

This way you can detect errors while cron is processing the script.

Your last comment indicates that there might be auth problems with bitbucket. To make sure you push in the right way I would advise to always write out the full target for git inside scripts. So try to use

git push --all origin instead of git push all;

The please check your git settings to use ssh and not https when pushing to bitbucket.

You can also specify the host and ssh key to use in your /root/.ssh/config

Host bitbucket
  HostName bitbucket.org
  User YOUR_USERNAME
  IdentityFile /root/.ssh/id_rsa
  IdentitiesOnly yes

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

scheduled and customized git add, commit, push cron job

From Dev

Set cron job issue

From Dev

Redmine Cron Job Issue

From Dev

Cron Job issue Magento

From Dev

Cron job not auto runs inside a Docker container

From Dev

auto submit form using cron job

From Dev

cron git push with ssh key

From Dev

Issue w/ Git push

From Dev

git push update issue

From Dev

git push update issue

From Dev

Authentication issue with cron job on Ubuntu 18.04

From Dev

Adding cron job in openshift without using git

From Dev

Git push origin master issue

From Dev

git push to github via cron on mac

From Dev

Git Pull and then Push via Cron in Ubuntu

From Dev

Authenticate Mongodb and Auto Backup of Database on Server Using Cron Job

From Dev

Cron Job to auto delete folder older than 7 days in Centos

From Dev

Jenkins job: Could not push to git from shell

From Dev

I'm having issue with rtcwake being run from a Cron job

From Dev

website backup via cron job and "file changed as we read it" issue

From Dev

Auto commit and auto push changes in local repo to git

From Dev

Expected Committer Name Git Push Issue

From Dev

GIT: Can't Push (Strange Config Issue)

From Dev

Git first pull and push to master issue

From Dev

Git first pull and push to master issue

From Dev

Jenkins job hangs on "git push origin branch" due to authentification

From Dev

Jenkins Release artifact job running on Windows fails in Git push command

From Dev

Jenkins Release artifact job running on Windows fails in Git push command

From Dev

Jenkins job hangs on "git push origin branch" due to authentification