[Git + cron]: Schedule your git commands with cron job
git
bash
11/21/2019
Note: cron has been deprecated in favor of launchd on macOS
launchd:
In computing, launchd, a unified operating system service management framework, starts, stops and manages daemons, applications, processes, and scripts in macOS. It was introduced with Mac OS X Tiger and is licensed under the Apache License — Wikipedia
More information about launchd is handled in this post
Using git commands with cron scheduler
Create a repo
If you haven't set up SSH key
Please follow this post to link your SSH key on your machine with your GitHub account before proceeding
Create a file that'll be pushed
vim READ.md
## This file will be pushed to github repo with cron
Then save
Create .sh script
newrepo.sh (Example)
git initgit add README.mdgit commit -m "[INITIAL]: initial commit 🔥"git remote add origin https://github.com/EllisMin/auto-pushed-contents.gitgit push -u origin master
Save it then grant executable permission with
chmod +x newrepo.sh
Check your computer's time
date
Schedule with cron
sudo crontab -e
sudo allows you to run script as root
10 9 21 03 * cd ~/Desktop && ./newrepo.sh# Minute | Hour | Date | DayOfWeek | Script
The shell script will be run at 03/21 at 9:10AM
Outputting result into file
10 9 21 03 * cd ~/Desktop && ./newrepo.sh > /tmp/result 2>&1
Output result in
/tmp/result
2&>1
indicates that standard error is redirected to/tmp/result
View list of active crontab jobs
sudo crontab -l
Ran into trouble? (macOS)
If somehow doesn't work, try giving Full Disk Access to /usr/sbin/cron
and /usr/bin/crontab
on System Preference > Security & Privacy > Privacy > Full Disk Access
. Press command + shift + G
to open go to folder to type in manual directory.
More Examples
11 13 * * 1-5 /some/dir/script.sh
Execute every business day at 1:11PM
*/10 * * * * /some/dir/script.sh
Execute every 10 minutes
Schedule your mac to wake up
cron
doesn't execute while your computer is asleep, but you can schedule your computer to awake a minute before scheduled cron job.
For macOS: Preference
>> Energy Saver
>> Schedule
Check logs
On linux, cron job gets logged at
/var/log/system.log
Use the following to filter cron jobs
grep CRON /var/log/system.log