I'll show you how to get your PC to do the work on a regular basis using a command called crontab. You can use crontab on a mac with UNIX-like commands, or you can run batches on the server on a regular basis. It's the perfect command to get your PC to work. Let's see how to actually use it. This time, I will show you how to automatically execute git pull to keep the local repository up-to-date.
--Caution for crontab command --Description of crontab --Description in shell script
The crontab command is basically executed in combination with options. However, since there are notes, once check how to use with man
-l Display the current crontab on standard output. -r Remove the current crontab. -e Edit the current crontab using the editor specified by the VISUAL or EDITOR environment vari- ables. The specified editor must edit the file in place; any editor that unlinks the file and recreates it cannot be used. After you exit from the editor, the modified crontab will be installed automatically.
By adding -l, you can see the current current state, By adding -r, you can delete crontab, You can edit by adding -e.
Crontab can be created for each logged-in user.
[The thing to be very careful about here is the difference between the options
-e and -r. Since e and r are next to each other on the keyboard, if you make a mistake, it will be irreparable. Before you get used to it, you should always use man crontab to check which one you have before running it.
In crontab, write the schedule and the command to be executed. This time I will write a shell script and execute it.
You can specify minutes, hours, days, months, and days of the week. This is the order from the left. If it is *, it will not be specified, and if it is * / 2, it will be executed every other time.
*/5 * * * *
This is every 5 minutes
0 23 * * *
This is 23:00 every day
* */1 * * *
This will be every hour.
If you want to write in more detail, I think you should refer to this article etc.
Let's touch cron-Qiita
Please write down the absolute path. This time, write a shell script under / root.
Just write this next to the schedule.
*/5 * * * * /root/gitpull.sh
After editing crontab, restart it for reloading.
service crond restart
Description in shell script
Let's write git pull.sh.
cd (Go to the directory of the project you want to git pull) git fetch git reset --hard origin/master git merge origin/master
For the time being, only the basic type.
git fetch git reset --hard origin/master
Brings the latest state of the remote to origin / master. You can apply changes to local files by reflecting the latest state in master with git merge.
In other words, you're just doing git pull
Please refer to this as well
that's all. If you run it every 5 minutes, the latest state of git will always be reflected. It's convenient.