INSTALL AND RUN CRONJOB ON UBUNTU
Steps:
-
install cronjob with command
sudo apt-get install cron -
start cronjob with command
sudo service cron start -
check the status of cronjob with command
sudo service cron status -
create a .sh script for the execution to be done by cronjob (example: /home/ferdyhape/tes-cron/tes-cron.sh)
-
(optional) command
select-editorto choose the editor used to edit crontab -
add the script to the cronjob with the command "crontab -e", with the format
# min hour day month day_of_week command * * * * * /bin/bash /home/ferdyhape/tes-cron/tes-cron.sh -
save the changes and exit the editor
-
check the cronjob list with the command "crontab -l"
-
check the cronjob log with the command "grep CRON /var/log/syslog"
Note:
- For the script to be executed by cronjob, the script must have execute permission. Give execute permission with the command
chmod +x /home/ferdyhape/tes-cron/tes-cron.sh - The cronjob will run every minute, to change the schedule, adjust the time in the format "min hour day month day_of_week command"
- To stop the cronjob, use the command
sudo service cron stop - To restart the cronjob, use the command
sudo service cron restart - To remove the cronjob, use the command
crontab -r