What command can I use to schedule a recurring task on linux? I would also like to send the command return by email automatically. What is the most suitable tool?
There is a tool for linux called crontab. She is native. For you to edit the file just give the command
crontab -e .
The crontab has the following format:
[minutes] [hours] [days of the month] [month] [days of the week] [user] [command]
Filling in each field is done as follows:
- Minutes: enter numbers from 0 to 59;
- Hours: enter numbers from 0 to 23;
- Days of the month: enter numbers from 0 to 31;
- Month: enter numbers from 1 to 12;
- Days of the week: enter numbers from 0 to 7;
- User: is the user who will execute the command (it is not necessary to specify it if the user's own file is used);
- Command: the task to be performed.
- crontab -e: used to edit the current crontab file and create one if it doesn't exist;
- crontab -l: show the current contents of crontab;
- crontab -r: remove the current file from crontab.
To send email, just use this command
59 */6 * * * script.sh | mail -s “Subject of Mail” firstname.lastname@example.org
You can read more about this link. http://en.wikipedia.org/wiki/Cron