How to Add a Shell Script to Cron

Unix systems, including Linux and Mac OS X, use a program named Cron to schedule the performance of regular tasks. Cron can perform tasks once per minute, at most. But it is also possible to define task for once a year.

Instructions

    • 1

      Open a terminal. Under Mac OS X, you can do this by clicking "Spotlight" and typing "Terminal." Under other Unix systems, the procedure will depend upon your configuration, but normally there is a terminal or shell shortcut in the menu.

    • 2

      Type the following to open a temporary cron tab file for your current user:

      crontab -e

      This will use the default terminal text editor for your system, and it will open a temporary file. When you exit the program, "crontab" will automatically merge your changes into the cron system. This is done to prevent errors.

    • 3

      Type at what minute you want the task to occur in the first column. If you want the task to occur every minute, type "*." If you want it to occur every five or 10 minutes, type "*/5" or "*/10," as appropriate. Hit "Tab" when you finish.

    • 4

      Type the hour at which you want the task to occur, using a number between 0 (midnight) and 23 (11 p.m.). Once again, to have a task occur every hour, you may type "*" or "*/5" for every five hours. This format will continue for all of the times in your script. Press "Tab" when you finish.

    • 5

      Type the day of the month on which you want the task to occur, and hit "Tab."

    • 6

      Type the day of the week on which you want the task to occur as a number between 0 and 7. Both 0 and 7 refer to Sunday. Press "Tab."

    • 7

      Type the command to be run.

Tips & Warnings

  • Always use "crontab -e" to edit your cron. Modifying cron tab files directly can cause problems for your system.

  • On some systems, the "run" portion in step 7 cannot contain any "." It may be necessary to rename your script so that the file name does not contain any periods.

  • Cron does not notify the user in any way that a script has failed to run, so always test your cron tab by scheduling a nearby time before committing the real time.

Related Searches:

References

Comments

You May Also Like

  • How to Add a Cron Job

    Cron is a UNIX utility that execute programs at regular intervals. Each user and root can specify his own set of commands...

  • How to Run Mac OS X Maintenance Scripts

    Mac OS X automatically runs maintenance scripts in the background on a schedule. These scripts delete temporary files, remove outdated log files...

  • How to Calculate Keystrokes Per Minute

    While words per minute (WPM) is one of the most common ways to report typing speed, some people prefer keystrokes per minute....

  • How to Write a Shell Script in Unix

    Under UNIX, and UNIX-like operating systems such as Linux and Mac OS X, shell scripting makes the automation of tasks much easier....

  • How to Use Cron

    Cron is a scheduling program used in all Linux and Unix operating systems. Linux and Unix users tell cron to run a...

  • How to use SSH for Mac OS X

    ssh - OpenSSH client (remote login program) for the Mac OS X Terminal is a secure way of logging into a remote...

  • How to Schedule a Job in Unix

    The cron clock daemon enables the UNIX system administrator to schedule tasks for automatic execution at any time of the day or...

  • How to fix BAD FILE MODE Cron errors

    Inside Logwatch, its common to see errors such as "BAD FILE MODE" appear at the end of the crontab section. it should...

  • How to Write a Script in Linux

    When you're working in a Linux environment, you often need a script to complete a task for you, interact with a user...

Related Ads

Featured