Wednesday, January 27, 2010

Setting Crontabs in Mac OS X

It has been a while since I last posted, but I have a new tutorial for everybody... Settings cron jobs through the "crontabs" command in an SSH terminal.

To start, open up the terminal, and type ssh myUsername@myUrl. The terminal program will then prompt you for your password to access the remote server.

Once you have been successfully authenticated and logged into your remote server, you may then begin sending commands to it.

The basic crontab commands:

crontab -l   (display the currently loaded cron jobs on the server)

crontab -e   (add, edit, and delete individual cron jobs on the server, this will be displayed as a table)
  • Once this command has been issued, you simply begin typing text to invoke the INSERT mode.
  • Example cron: */5 * * * * http://myurl.com/index.php
    • This cron simply runs the "http://myurl.com/index.php" url every 5 minutes
    • Use the format [minutes (0 - 59)] [hours (0 - 23)] [day of month (1 - 31)][month (1 - 12)][day of week (0 - 6)] [COMMAND]
  • When you are done editing your scheduled cron jobs, simply press ESC, and type :wq to save the changes to the server.
  • That is it for editing crons!

crontab -r   (CAUTION: removes all crontabs stored on the server's crontab file)

crontab -v   (display the last time the crontab file was edited on the server)


If you do not want to type ssh myUsername@myUrl each time you connect, go into the Mac OS X terminal 's top bar and go into the "Shell" drop-down. Once there go to "New Remote Connection..." and add your remote server's details through the graphical interface.

Thanks for visiting my blog!


No comments:

Post a Comment