Tuesday, January 19, 2010

Countdown 5 4 3 2 1 0 Techno Song

cron: automate processes

Problem: automatically start the execution of a process.

Solution: The automatic execution of programs based on a set schedule can be easily accomplished in a "unix" due to command "crontab" . For example, imagine that it provides a script "backup.sh" to run the backup copy of a selection of important documents on an external drive. To begin with we create a hidden directory type ". Cron.daily" in our home, copiamoci file "backup.sh" in and make it executable

  1. mkdir. Cron.daily

  2. backup.sh cp / home / username (replace with your username). cron.daily /

  3. sudo chmod + x / home / username / .cron.daily / backup.sh


processes that are executed by cron are listed in special files. At the system level processes are listed in the file / etc / crontab, user-level is not possible to create a crontab file in your home, for example, we can create a hidden file. Crontab

Here is a sample crontab

# minute hour mday month wday command

15 03 * * * sh / User / login_name / .cron.daily / backup.sh

15 03 1 * * sh / User/nome_login/.cron.daily/Sample1

15 03 * * 6 sh / User/nome_login/.cron.daily/Sample2

* / 15 03 * * * sh / User/nome_login/.cron.daily/Sample3

In the first line are the header files that specify the meaning of the different entry starting from the second line. The entries are grouped in columns separated by a tab.

The second line corresponds to the performance of the backup script, which was launched at 03:15 every day of the week (wday) for all days (mday) of every month (month). The asterisks mean always.

There are other examples:

Line 3: run the command sample 1 at 3:15 only one day of each month.

Line 4: run the command sample 2 at 3:15 of 6 days each week.

Line 5: Run 3 control samples every 15 minutes.

to variables for cron tab you can assign the following parameters

"minutes" 0-59 "hours" 0-23, "mday2 1-31," wday "0-7 (0 and 7 = Sunday), or with the first three letters of the day (eg, "Thu" for Thursday), 1-12 month, or with the first three letters of the month (eg "Jan" for "January") .

You can also set intervals or sequences (separated by commas). For example, in the column for 8-11 hours will be associated with the execution of a command to the 8, 9, 10, and 11. A sequence such as 1 , 2,5,9 in the column of hours will be associated with the execution of the script at 1, 2, 5, and 9.

Once created and placed on script and crontab to do is start the process by typing:

crontab / Users / login_name / .crontab

to stop cron run the command:

crontab-r

While print screen the list of processes run by cron just type

cronta-l

is important to periodically check what processes are in operation since crontab may occasionally stop for example on the occasion of 'software update.


0 comments:

Post a Comment