Ubuntu – Cronjob once a day in Ubuntu 12.04


I have setup a VPS with Ubuntu 12.04 and now I want to run a cronjob once a day.

The command line is as follows:

    mono /root/Folder/Aplication.exe

I've looked and looked around the internet but cant seem to understand how to do it.
I for instance want to run this command every 24 hours at midnight.

Thank you in advance for reading my question and of course for all the answers.

Best Answer

Because there are some complementary differences between @Guss's and my answer, I will leave it.

Here you are an illustration about cronjobs setup (source):

* * * * * command to be executed
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)
  • If you want to run a job by your $USER every day at 0:15 o'clock, you need to edit user's crontab file (which is located in /var/spool/cron/crontabs/<user_name>). You can do that by the command crontab -e. (Maybe there will be appeared a dialog, where you must choose the default terminal text editor.) In the end of the crontab file add next line:

    15 0 * * * /usr/bin/mono /root/Folder/Aplication.exe > /var/log/mono.daily.log 2>&1
    • /usr/bin/mono it's recommended to use full path to the command in Cron. To find it you can use sudo updatedb && sudo whereis mono.
    • > /var/log/mono.daily.log this part will redirect the output to a log file, in case you want to trace what is happen with your cronjob. If you want to keep log data from the previous days, you can use >> instead of >.
    • 2>&1 this part will put the error messages into the log file.
  • If you want to run a job by root, you must edit its crontab file: sudocrontab -e and add the line shown above.

  • Also, for daily cronjobs, you can add an executable file in the folder /etc/cron.daily. To find an example, check some of existing files into this folder.

Related Question