Create Auto Git Push Using Crontab in Ubuntu

Pada posting berjudul kali ini akan dibahas cara membuat cronjob untuk auto push ke remote repository.

Create File Bash (ekstensi .sh)

> vi nama_file.sh

Kemudian pencet huruf i untuk insert dan lanjutkan mengisi isi file seperti dibawah ini.
Jika git push menggunakan https maka perlu menyertakan user dan password.

#!/bin/bash

cd /home/jupyter-name/folder_git
/usr/bin/git add .
/usr/bin/git commit -m "Auto commit `date`"
/usr/bin/git push -f https://user:password@github.com/user/name.git branch_name

ketik :wq untuk menyimpan

Catatan:
Di Windows kita tidak bisa menggunakan `date` untuk mendapatkan tanggal komputer.
Silahkan baca artikel "Create Auto Push Git in Windows"

Grant Execute .sh File

> chmod +x /home/name-agus/nama_file.sh

Save Credential For Git

Sebelum melanjutkan maka kita perlu menyimpan user dan passwor git sebab kita menggunakan https dan bukan ssh utk koneksi ke remote repository.


$ git config credential.helper store
$ git push https://github.com/owner/repo.git

Username for 'https://github.com': <USERNAME>
Password for 'https://USERNAME@github.com': <PASSWORD>

Reff :
Jika ingin menyimpan user dan password untuk waktu tertentu
https://git-scm.com/docs/git-credential-cache

Create Crontab

Recurrence every 10 minutes

> crontab -e

*/10 * * * * /home/jupyter-name/cron_bash/cron_job.sh > /home/log.txt

:wq

Untuk pembuatan cronjob silahkan ikuti link dibawah ini :

link : https://www.geeksforgeeks.org/crontab-in-linux-with-examples/

Check existing Crontab

> crontab -l

Check log Crontab

> grep cron /var/log/syslog


Semoga posting berjudul "Create Auto Git Push Using Crontab in Ubuntu" diatas dapat bermanfaat.


Salam,

Popular posts from this blog

Permission Rule In SharePoint List or Library

Audits Or Change Data Capture In SQL Server

Login failed for user (Microsoft SQL Server, Error: 18456)