Increase your Linux/Unix Productivity: How to use crontab زيادة الخاص بك لينكس / يونكس الإنتاجية : كيفية استخدام crontab

by Sukrit Dhandhania on November 17, 2008 من جانب Sukrit Dhandhania 17 تشرين الثاني / نوفمبر ، 2008

لينكس

Apart from video games one of the great advantages of using computers is that they don’t seem to mind doing boring and repetitive tasks that we would rather not do. وبصرف النظر عن ألعاب الفيديو واحد من أعظم مزايا استخدام الكمبيوتر هو أنهم لا يبالون به التكرار الممل والمهام التي نحن نفضل ان لا تفعل. For monotonous tasks such as running daily backups we are better off scheduling them to run at a certain time every day, and do more interesting stuff with our time. لرتابة المهام اليومية مثل تشغيل النسخ الاحتياطي أننا سنكون أفضل حالا تحديد مواعيد لهم لتشغيل في وقت معين كل يوم ، وتفعل أشياء أكثر إثارة للاهتمام مع عصرنا. Linux and UNIX usually come with the utility “crontab” by default. لينكس ويونيكس وعادة ما تأتي مع فائدة "crontab" بشكل افتراضي. This very useful command allows you to schedule tasks to run at a specified time and repeat as configured. هذا مفيد جدا للقيادة يسمح لك الجدول الزمني لإدارة المهام في وقت معين وتكرار ما تهيئتها. A task scheduled using “crontab” is called a “cron job”. وهناك مهمة المقرر باستخدام "crontab" يسمى "كرون الوظائف".

The crontab command allows you to instruct your server to execute a script at a specified minute of the specified day of the particular month. وقد crontab يسمح لك بتشغيل إصدار تعليمات إلى الخادم الخاص بك لتنفيذ البرنامج النصي في لحظة محددة من يوم محدد من شهر معين. To see what cron jobs are setup to run on your machine, run the following command: كرون لنرى ما هي وظائف الإعداد لتشغيل الجهاز الخاص بك ، قم بتشغيل الأمر التالي :

# crontab -l # crontab - ل

If your machine has some cron jobs configured it will display something like the following: وإذا كان جهازك قد كرون بعض وظائف تكوين سيحتوى على شيء من هذا القبيل ما يلي :

0 6 * * * /opt/scripts/backup_script.sh 0 6 * * * / اختيار / مخطوطات / backup_script.sh

The crontab configuration above shows a cron job that executes the shell script “backup_script” everyday at 6 AM. وقد crontab التكوين أعلاه يظهر كرون الوظائف التي تنفذها شل في البرنامج النصي "backup_script" اليومية في 6 صباحا. The * means to run at every instance of the value in the field. * فإن وسائل لتشغيل في كل حالة من الحالات من قيمة في الميدان. So an asterisk in the day, month, and day of week fields in the above example means that the script should run every day of the month, every month of the year, and every day of the week. والنجمة في ذلك اليوم ، الشهر ، واليوم من الأسبوع في المجالات المذكورة أعلاه مثلا يعني أن النص يجب أن يدير كل يوم من الشهر ، كل شهر من السنة ، وكل يوم من أيام الأسبوع. The first and second fields tell crontab to execute the script at zero minutes and six hours, which is 6 AM. الأولى والثانية الميادين اقول crontab لتنفيذ البرنامج النصي في الصفر ست ساعات ودقائق ، الذي هو 6 صباحا. So, this cron job configuration would read something like this, “Run the script /opt/scripts/backup_script.sh at zero minutes, 6 AM, every day, every month, and every day of the week.” Below is the “anatomy” of a crontab configuration explained. لذا ، هذا كرون وظيفة التشكيل على النحو التالي شيئا مثل هذا ، "قم بتشغيل البرنامج النصي / اختيار / مخطوطات / صفر في backup_script.sh دقائق ، 6 صباحا ، كل يوم ، كل شهر ، وكل يوم من أيام الأسبوع." فيما يلي هو "علم التشريح "من التشكيل وأوضح crontab.

0 6 * * * /opt/scripts/backup_script.sh 0 6 * * * / اختيار / مخطوطات / backup_script.sh
|  |  |  |  | | | | | |
|  |  |  |  |________________ day of week (Sunday=0) | | | | |________________ يوم من الأسبوع (الأحد = 0)
|  |  |  |__________________ month of year | | | |__________________ الشهر من العام
|  |  |____________________ day of month | | |____________________ يوم من الشهر
|  |______________________ hour of day | |______________________ من ساعة في اليوم
|________________________ minute of hour |________________________ دقيقة من ساعة

To schedule new cron jobs or to edit old ones execute the following command: الجدول الزمني لكرون وظائف جديدة أو لتحرير القديمة تنفيذ الأمر التالي :

# crontab -e # crontab - ه

This will bring up an editor with which you can add, edit, or delete “cron jobs”. هذا وسوف يطرح مع رئيس تحرير التي يمكنك إضافة أو تحريرها أو حذفها "كرون الوظائف". To schedule a job to run at 3:45 PM every Monday add entry like this: الجدول الزمني لعمل لتشغيل في 3:45 مساء كل يوم اثنين إضافة مثل هذا الدخول :

45 15 * * 1 /opt/scripts/script.sh 45 * 15 * 1 / تختار / مخطوطات / script.sh

You can also use a comma to add multiple entries into a field. يمكنك أيضا استخدام فاصلة إضافة إلى دخول عدة مرات الى الميدان. This is useful if you want to run a script thrice a day, with an eight hour interval. وهذا مفيد إذا كنت تريد لتشغيل البرنامج النصي ثلاث مرات يوميا ، مع ثماني ساعات الفاصلة. Make sure you do not leave space between entries in a single field, though. تأكد من عدم ترك الفضاء بين الدخول في ميدان واحد ، وإن كان. Your “cron job” entry would look like this: الخاص بك "وظيفة كرون" أن دخول مثل هذا :

0 1,9,17 * 2,11 * /opt/scripts/db_backup_script.sh 0 1،9،17 * 2،11 * / اختيار / مخطوطات / db_backup_script.sh

In the above example the script “db_backup_script.sh” runs at 1 AM, 9 AM, and 5 PM every day in the months of February and November. في المثال السابق السيناريو "db_backup_script.sh" تدير في 1 صباحا ، 9 صباحا و 5 مساء كل يوم في شهري شباط / فبراير وتشرين الثاني / نوفمبر. There are a lot of cool things that you can do with cron jobs. هناك الكثير من الأشياء التي تبرد يمكنك القيام به مع كرون الوظائف. The same works for day, month, and day of week. وتعمل لنفس اليوم والشهر ، واليوم من الاسبوع. Once you get the hang of this try out the following. وبمجرد حصولك على شنق هذا من تجربة التالية. Crontab doesn’t only understand numbers, it can also operate on some basic English words: Crontab لا تفهم إلا أعداد ، كما يمكن أن تعمل على بعض الكلمات الانجليزية الأساسية :

string explanation سلسلة تفسير
—— ———– -- ----
@reboot Run once, the next time the system reboots @ إعادة تشغيل الكمبيوتر مرة واحدة ، في المرة القادمة النظام يعيد الإقلاع
@yearly Run once a year, at the beginning of the year @ سنويا تشغيل مرة واحدة في السنة ، في بداية السنة
@annually Same as @yearly, run once annually @ @ سنويا نفس ما ورد في السنة ، مرة واحدة سنويا
@monthly Run once a month, at the beginning of the month @ الشهري تشغيل مرة واحدة في الشهر ، في بداية شهر
@weekly Run once a week, at the beginning of the week @ الأسبوعية تشغيل مرة واحدة في الأسبوع ، في بداية الأسبوع
@daily Run once a day, at midnight @ يوميا مرة واحدة فى اليوم ، في منتصف الليل
@midnight Same as @daily, run at midnight @ @ نفس منتصف الليل يوميا ، في منتصف الليل البعيد
@hourly Run once an hour, at the beginning of the hour @ مرة واحدة كل ساعة تشغيل ساعة ، في بداية من الساعة

So, for example, if you want to run a script at midnight every night, this is what your crontab configuration would look like: ذلك ، على سبيل المثال ، إذا كنت تريد لتشغيل البرنامج النصي عند منتصف الليل كل ليلة ، وهذا هو ما crontab التكوين الخاص بك سوف تبدو مثل :

@midnight /opt/scripts/script.sh @ منتصف الليل / اختيار / مخطوطات / script.sh

Using “@midnight” rather than “0 0 * * *” will work the same and execute the requested script at midnight every night while being a lot more readable than its numerical counterpart. استخدام "@ منتصف الليل" بدلا من "0 0 * * *" ستعمل نفس وطلب تنفيذ البرنامج النصي في منتصف الليل كل ليلة في حين يجري الكثير للقراءة أكثر من نظيره العددي. You can also make the use of hyphens to declare a range. يمكنك أيضا استخدام الشرطات لتعلن مجموعة. In the command below “script.sh” will be executed at the beginning of every hour from 1 AM to 6 AM: في أقل من قيادة "script.sh" سيتم تنفيذها في بداية كل ساعة من 1 صباحا الى 6 صباحا :

0 1-6 * * * /opt/scripts/script.sh 0 1-6 * * * / اختيار / مخطوطات / script.sh

There are many more cool things you can do with cron. وهناك العديد من الأشياء أكثر بارد يمكنك القيام به مع كرون. Every sysasmin swears by it, it’s pretty easy to use once you get the hang on it, and very powerful. كل sysasmin أقسم أنه ، من المهم جدا سهل الاستخدام بمجرد حصولك على شنق ، وقوية جدا. Use this tool wisely, as scheduling a task wrongly can sometimes do a lot of harm. استخدام هذه الأداة بحكمة ، وتحديد مواعيد مهمة خطأ في بعض الأحيان يمكن أن تفعل الكثير من الضرر. Reading the “man page” of crontab would be highly recommended. قراءة "رجل صفحة" من crontab وأكون ممتنا للغاية الموصى بها.

Related Posts: الوظائف ذات الصلة :
  • 5 Desktop Wallpapers that will increase your productivity 5 خلفيات سطح المكتب الخاص بك من شأنها أن تزيد الإنتاجية
  • Update: Gmail increases storage to 4.2GB تحديث : Gmail زيادات لتخزين 4.2GB
  • How to create automated Linux/Unix backups كيفية إنشاء آلية لينكس / يونكس النسخ الاحتياطي
  • 3 Tools to increase iWeb functionality 3 أدوات لزيادة وظائف iWeb
  • How to use dstat to monitor your Linux/UNIX server كيفية استخدام dstat لرصد الخاص بك لينكس / يونيكس خادم
  • Get Simple Help tutorials just like this one in your email inbox every day - for free! الحصول على مساعدة بسيطة مثل هذه الدروس واحد في صندوق الوارد في بريدك الإلكتروني كل يوم -- لالحرة! Just enter your email address below: فقط أدخل عنوان بريدك الإلكتروني أدناه :

    You can always opt out of this email subscription at any time. يمكنك دائما أن تختار الانسحاب من الاشتراك في هذا البريد الإلكتروني في أي وقت.


    Bookmark and Share المرجعية والاسهم

    { 0 comments… (0 التعليقات... add one now إضافة واحد الآن } )

    Leave a Comment ترك التعليق

    You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> يمكنك استخدام هذه العلامات والصفات هتمل : <ahref="" title=""> <abbrtitle=""> <acronymtitle=""> <b><blockquotecite=""> <cite><code> <deldatetime=""> <em><i><qcite=""> <strike><strong>