I need the exact code that I would use because I'm not able to figure it out. I use crontab -e
to set up a cron job but when I save it, it never works. I'm also just trying to run a file called newmail.sh
from the root user.

- 58,122

- 101
- 1
- 1
- 3
-
Have you find the answer to your question? – bendaf Jan 23 '19 at 13:21
3 Answers
If you wanted the task to run every day at 3:17pm, you would use in /etc/crontab
or files in /etc/cron.d
:
17 15 * * * root newmail.sh
This says "run newmail.sh as root every day of the week, every day of the month, every month at 3:17pm."
minute hour dom month dow user cmd
minute - This controls what minute of the hour the command will run on, and is between '0' and '59'
hour - This controls what hour the command will run on, and is specified in the 24 hour clock, values must be between 0 and 23 (0 is midnight)
dom - This is the Day of Month, that you want the command run on, e.g. to run a command on the 19th of each month, the dom would be 19.
month This is the month a specified command will run on, it may be specified numerically (0-12), or as the name of the month (e.g. May)
dow - This is the Day of Week that you want a command to be run on, it can also be numeric (0-7) or as the name of the day (e.g. sun).
user - This is the user who runs the command.
cmd - This is the command that you want run. This field may contain multiple words or spaces.
from: http://www.unixgeeks.org/security/newbie/unix/cron-1.html
-
-
on Ubuntu 19 the minute is first. Also, it warns you about incorrect time. – kelalaka May 18 '20 at 22:27
-
The user crontab edited by
crontab -e
never supported the username field. The quoted text is for/etc/crontab
. – muru Oct 22 '21 at 09:29
sudo crontab -e
Add these lines in end of file
*/1 * * * * wget -O /dev/null project_crone_URL
(Run cron per once in 1 minute)
0 0 * * * wget -O /dev/null project_crone_URL
(Run cron per once in 24 hours)
save file
Start crontab by this command
sudo /etc/init.d/cron start
Stop crontab by this command
sudo /etc/init.d/cron stop
Restart crontab by this command
sudo /etc/init.d/cron restart

- 22,691

- 81
If you use crontab -e
since Ubuntu 16.0+ will not have the user field, so the correct format is:
17 15 * * * newmail.sh
This says "run newmail.sh every day of the week, every day of the month, every month at 3:17pm."
Other ways dm78's answer is correct and contains the exact description of the format.
Also if something goes wrong and you have a mail system installed it will send you a message. For more info see this answer
If you are interested in logging of cronjobs, you can use this answer.

- 163
-
3It depends on which crontab you edit. The
crontab -e
thingy does not have a user field (as you correctly say) but the file/etc/crontab
(the socalled system crontab) and the files below/etc/cron.d
do have a user field. – PerlDuck Jan 23 '19 at 18:45