Cron job is one of the best ways to automate various daily, weekly or even monthly tasks. Cron jobs are widely used these days because doing the same things manually over and over again is time-consuming and inefficient. In this tutorial, we will learn how to set up a cronjob on a server which runs Webmin.
What you’ll need
Before you begin this guide you’ll need the following:
A working server / VPS with Webmin installed
Access to your Webmin admin panel
Step 1 — Accessing cron job configuration section in Webmin
Login to your Webmin admin panel. You can usually do this by typing https://your-vps-ip-adress:10000 (replace your-vps-ip-address with the dedicated IP address of your server) into your browser.
Choose Webmin between two options at the top of the left sidebar.
Find and click System tab in the left sidebar of Webmin and navigate to Scheduled Cron Jobs.
You should now be able to see a window with all of your scheduled cron jobs. Usually, it is filled with many default cron jobs of Webmin or other services. If you see a page like this, you are in the correct place.
Step 2 — Creating a new cron job
Click Create a new scheduled cron job listed at the top of the cron job list.
In the next page, you will need to configure your cron job. The first section is called Job Details. Here you will need to configure:
Execute cron job as – you need to select which UNIX user should execute the cron job. By clicking the button on the right side from the field, you will get a full list of all available users on the server.
Active? – You can select whether your cron job should be active or not right after creation. You can surely change this setting later if, for example, you want to only activate the cron job later and not instantly upon creation.
Command – Here you will need to write command you want to run periodically. In this example, I am running a shell script so I only filled in the path of the file I want to execute. But you can write any command you like.
Input to command – This field will be fed to the command as input when cron job is executed. If, for example, your command was mail email@example.com , input entered into the field would be sent to that email address. (Note: this field is optional)
Description – your own cron job description (it is not required) for self-reference.
Next section on this page is called When to execute. Here you will be able to select when your cron job should be executed. There are two options:
Simple schedule – you can select an already defined interval from the drop down list.
Times and dates selected below – If you choose this option, you will have to configure the cron job execution times manually by selecting minutes, hours, days, etc. from the lists below.
The last section is called Date range to execute. In this section, you can set a date interval if you only need your cron job to run for a week/two weeks or any other time period.
Select Run on any date if you want the cron job to be active until you disable it.
Select Only run from … to … and fill in exact dates if you want to set a date interval for the cron job to be active.
When you have everything configured as you want, scroll down to the bottom of the page and click Create.
If the cron job was setup successfully, You will see it in the list of cron jobs:
You have learned how to setup a cron job on server/VPS running Webmin. Cron jobs will surely improve your efficiency by automating various tasks you had previously executed manually.
Linas started as a customer success agent and is now a full-stack PHP developer at Hostinger. He is passionate about making a positive impact on people by utilizing user-driven development techniques. As much as he enjoys coding and changing the world, he secretly dreams of becoming a rock star.