VDS Sphera Knowledge Base
| Main / Browse Categories / Other Software / Cron / How do I use Cron? |
How do I use Cron?
Cron allows you to set up programs to run at regular intervals as you need them to, at any time of day or night.
You start by logging into your VDS via SSH and changing directories:
cd /var/spool/cron/You will see a file that is named the same as your VDS username. You can edit that file using VI: vi filenameIf you have never edited the file, it most likely has one setting: 22 0 * * * /bin/logrotate /etc/logrotate.conf 2>&1 > /dev/nullA crontab entry is in the basic format: time actionTo set a time, you use the format: MI HR DM MO DW MI = A minute from 0 through 59 HR = An hour in 24 hour time, from 0 to 23 DM = A day of the month, from 1 through 31 (or 28,29,30) MO = A month from 1 to 12. DW = A day of the week, starting with Sunday, from 0 to 6.You can also use an asterisk (*) for "Everything," and both commas and dashes to indicate sequences and ranges. So, this gives us: MI HR DM MO DW actionThe action is whatever you want cron to run when this time comes. Typically, the output will be e-mailed to you unless you specify something else to happen. An example of what you might put in the time portion of a crontab file if you wanted to remind yourself two hours early to pick the kids up from late school activities every Monday, Wednesday, and Friday afternoon at 5 pm is: 00 15 * * 1,3,5Remember, you want to send your reminder at 3 pm or 15:00 hours. Since we're not restricting ourselves to particular days of the month, there's an asterisk in that slot. We're also not restricting what months this happens in. Then, we want the first, third, and fifth day of the week. Now the action and for a reminder the user "john" can use mail to send an e- mail to himself. John would have to be a POP user in your VDS. If they are not an actual user, you would use their complete email address. For example, john@domain.com. echo "Do not forget" | mail -s "Pick up kids at 5 pm" john echo "Do not forget" | mail -s "Pick up kids at 5 pm" john@domain.comThis format places the text "Do not forget" in the message body and "Pick up kids at 5 pm" in the subject line. So, putting it all together, you'd have: 00 15 * * 1,3,5 echo "Do not forget" | mail -s "Pick up kids at 5 pm" johnNow save and quit from your crontab file and run the command: crontab
User Comments
|
||||||||
Attachments
| No attachments. |
Related Articles
|
|


