How to set a cron job by using the terminal in Ubuntu Server – DGi Host.com
- by dgihost.com
Setting up a cron job using the terminal in Ubuntu Server involves using the crontab
command to edit the cron table. Here’s how you can do it:
- Open Terminal: Log in to your Ubuntu Server via SSH or open a terminal window if you’re accessing it locally.
- Access the Cron Table: Enter the following command to open the cron table for editing:
crontab -e - Edit the Cron Table: This will open the cron table in a text editor (usually Nano or Vim). The cron table follows a specific format:
m h dom mon dow commandm
stands for minute (0 – 59)h
stands for hour (0 – 23)dom
stands for day of month (1 – 31)mon
stands for month (1 – 12)dow
stands for day of week (0 – 7, where 0 and 7 represent Sunday)command
is the command or script you want to execute
* * * * /path/to/your/command.sh
This will runcommand.sh
every minute. Replace/path/to/your/command.sh
with the actual path to your script or command. - Save and Exit: Save the changes and exit the text editor. In Nano, you can do this by pressing
Ctrl + X
, thenY
to confirm, and finallyEnter
. In Vim, you can do this by typing:wq
and pressingEnter
. - Verify the Cron Job: After saving the cron job, you can verify that it was added correctly by running:
crontab -l
This command will list all cron jobs currently set for the user.
That’s it! You’ve successfully set up a cron job using the terminal in Ubuntu Server. Make sure to test your cron job to ensure it runs as expected.
Setting up a cron job using the terminal in Ubuntu Server involves using the crontab command to edit the cron table. Here’s how you can do it: That’s it! You’ve successfully set up a cron job using the terminal in Ubuntu Server. Make sure to test your cron job to ensure it runs as expected.