Add cronjobs in your vps server

Posted on July 6, 2020

Login to your server first with ssh:

ssh root@<ip-domain>

List the existing cronjobs:

cronjob -l

Add new cronjobs: (first it will ask you to select a text editor)

cronjob -e

After saving the file, the cronjobs should start working.

Every command has these 6 parts:

(minute, 0-59) (hour, 0-23) (day of month, 1-31) (month, 1-12) (day of week, 0-6 / SUN-SAT) (command)

For example to if you want to clean up a folder every day at 3am:

0 3 * * * rm -R /var/www/temp/*

or do it every Sunday and Thursday:

0 3 * * 0,4 rm -R /var/www/temp/*

 

Check out these links, they can help you understand how to place the values and run the cronjobs in the schedule you want.

https://www.netiq.com/documentation/cloud-manager-2-5/ncm-reference/data/bexyssf.html

https://crontab.guru/

More info:

https://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/