Today's the day

向软件大牛炫耀我会焊单片机,向硬件大牛炫耀我会写 Rails,向软硬件大牛炫耀我生物,向软硬件生物大牛炫耀我会折腾期货 -_-bbb

给firefox投上一票
基于Gtk的BT客户端--Deluge

用cron定时执行任务

galeki posted @ 2007年5月27日 23:28 in Linux with tags linux 定期执行 cron crontab , 6895 阅读

假如你有一些任务要定期执行,比如清理磁盘、删除过期文件、发送邮件和提醒,这个时候可以用cron来帮你。

首先是安装,大多数发行版都预装了,Gentoo下的cron有许多种实现,可以用emerge --search cron来查看,这里用vixie-cron,因为功能比较完整,命令语法也比较通用。

# emerge vixie-cron

之后要启动cron服务:

# /etc/init.d/vixie-cron start

别忘了把cron加入到启动脚本中:

# rc-update add vixie-cron default

完成安装。

系统cron设定:/etc/crontab

通过 /etc/crontab 文件,可以设定系统定期执行的任务,当然,要想编辑这个文件,得有root权限。

让我们打开 /etc/crontab,看看cron的语法:

  1. # for vixie cron
  2. #
  3. # $Header: /var/cvsroot/gentoo-x86/sys-process/vixie-cron/files/crontab-3.0.1-r4,v 1.1 2005/03/04 23:59:48 ciaranm Exp $
  4. #
  5. #
  6.  
  7. # Global variables
  8. SHELL=/bin/bash
  9. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  10. MAILTO=root
  11. HOME=/
  12.  
  13. # check scripts in cron.hourly, cron.daily, cron.weekly and cron.monthly
  14. 0  *  * * *     root    rm -f /var/spool/cron/lastrun/cron.hourly
  15. 1  3  * * *     root    rm -f /var/spool/cron/lastrun/cron.daily
  16. 15 4  * * 6     root    rm -f /var/spool/cron/lastrun/cron.weekly
  17. 30 5  1 * *     root    rm -f /var/spool/cron/lastrun/cron.monthly
  18. */10  *  * * *  root    test -x /usr/sbin/run-crons && /usr/sbin/run-crons 

以上是一个默认的/etc/crontab文件,7~11行设定了执行任务时特定环境变量的值,MAILTO=root 指出出错信息发给root。

真正描述执行的任务在14~18行,每行代表了一个定期执行的任务,从前到后,分为3部分:

第一部分,一堆奇怪的数字和星号,这部分描述任务的执行周期和时间,后面我们将详细解释。

第二部分,上面的文件全部是"root",描述了执行任务时的用户。

第三部分,为需要执行的完整命令。

第一部分分为5个小部分,没部分可以是数字或者星号,分别代表了分钟、小时、日期、月份、周,让我们来看一个例子:

0   7   *    *   *    root    mpg123 ~/wakeup.mp3
分 时 日 月 周

星号,即代表不限制,上面的例子就是:每天的7点0分,都将执行mpg123 ~/wakeup.mp3,放首歌,把自己从睡梦中叫醒~

以下是各部分的取之范围:

 分钟 0~59
 小时 0~23
 日期 1~31
 月份 1~12
0~6

其中周的范围0~6,0代表星期天,1~6代表周一~周六。

让我们来看更多的例子:

0  4  * * 0     root    emerge --sync && emerge -uD world              #每周日凌晨4点,更新系统
0  2  1 * *     root    rm -f /tmp/*                                                    #每月1号凌晨2点,清理/tmp下的文件
0  8  6  5 *   root     mail  robin < /home/galeki/happy.txt             #每年56日给robin发信祝他生日快乐

假如,我想每隔2分钟就要执行某个命令,或者我想在每天的6点、12点、18点执行命令,诸如此类的周期,可以通过 “ / ” 和 “ , ” 来设置:

*/2   *   *   *   *           root      ...............      #每两分钟就执行........
0  6,12,18   *   *   *    root      ...............      #每天6点、12点、18点执行........

用户的cron: crontab命令

上面我们提到的 /etc/crontab 文件,只能指定系统定期执行的命令,如果用户想设定自己定期需要执行的命令的话,就要用到crontab命令,编辑自己的crontab文件。

首先,用户必须隶属于cron组才可以用crontab命令,可以用下面的命令把用户加入到cron组中:

# gpasswd -a galeki cron

crontab命令主要有3个参数:

-e : 编辑用户的crontab。

-l  : 列出用户的crontab的内容。

-r  : 删除用户的crontab的内容。

执行crontab -e,将自动打开编辑器,你可以编辑自己的crontab文件,语法和 /etc/crontab 文件一样,不同的只是,不必再指出执行的用户,编辑后保存即可。

crontab -l用来查看自己的crontab文件内能,crontab -r删除自己的crontab。

free steam card gene 说:
2017年12月28日 17:55

This game is a steam wallet play the online game.

Madalin Stunt Cars 2 说:
2019年1月05日 14:42

If there are many sad stories, share it with the people you trust. Sharing helps people get closer together and you also relieve some of that sadness.

IPL Betting Sites 说:
2020年2月13日 12:52

Gambling Online on Cricket and our favorite teams is fun. There are millions of people who engage in IPL betting sites and wager a considerable amount of money. However, you wouldn’t like to use the services of any shady, unreliable website when it comes to betting. This is why in this article, we have compiled a list of best IPL betting sites for IPL 2020.

SlimyMed 说:
2020年5月15日 19:26

Eine Situation mit Übergewicht ist niemals wünschenswert, da sie schwerwiegende gesundheitliche Komplikationen haben kann, wenn sowohl physische als auch psychische Aspekte berücksichtigt werden. Um dieser Krise ein Gefühl der Erleichterung zu verleihen, müssen wir zu Ihrer Rettung ‘slimymed’, eine Diätpille, die so programmiert ist, dass sie einen schnellen und dauerhaften Fettabbau zusammen mit einer Appetitkontrolle einleitet.

thomasyoung 说:
2020年11月03日 17:30

We TreatAssignmentHelp is a team of experts professional academic writers who provide Essay Writing Services, We will provide you the best essay writer in your subject with Online Accounting Assignment Help, Finance Assignment Help UK, etc will deliver your 100% original, plagiarism-free paper on time. For More Services: Assignment Help England | Sociology Dissertation Help | Essay Help Australia

Dini 说:
2020年11月07日 11:33

Tampil gaya dengan budget pas pasan juga tetap bisa kok. Ada banyak model tas selempang wanita yang kekinian dengan harga yang terjangkau. Cek di sini untuk info selengjkapnya, 5 Model Tas Selempang Wanita Murah Untuk Acara Santai. Untuk anak kecil hingga remaja juga kini tersedia banyak pilihan tas yang modis loh. Untuk kamu atau para Bunda yang ingin melengkapi gaya si kecil, cek informasi mengenai toko online yang menjual tas anak di sini ya, klik di sini. Apabila anda sedang mencari toko online yang menyediakan ragam varian tas modis, kekinian, dan terpercaya dengan harga yag terjangkau, simak informasinya di halaman ini 5 rekomendasi olshop tas murah. Buat kamu yang ingin berbelanja tas import, namun kerap khawatir tertipu olshop yang tidak amanah, kamu bisa berbelanja dengan aman di Shopee. Berikut ini rekomendasi olshiop tas yang menjual tas import bagus dengan harga murah, 5 Olshop Tas Selempang Wanita Import di Shopee. Untuk kamu yang berdomisili di Bandung, dan ingin berbelanja tas online tanpa khawatir dengan ongkir yang kemahalan, baca info mengenai toko tas online di Bandung yang menjual tas dengan harga terjangkau di link ini, 5 olshop tas murah Bandung. Kamu yang membutuhkan informasi tempat berjualan tas wanita model selempang murah, baik untuk dipakai sendiri ataupun untuk dijual lagi, bisa membaca artikel ini 5 Olshop Jual Tas Selempang Wanita Murah Kalau kamu mencari olshop tas yang lengkap, menyediakan banyak model tas untuk wanita, pria, dan anak-anak, silahkan baca info di artikel ini info lengkap. Yuk cari tahu informasi mengenai olshop tas wanita di Batam yang recommended banget buat para wanita di tautan ini, 3 Rekomendasi Olshop Jual Tas Wanita di Batam. Ada banyak olshop yag menjual tas murah di Shopee. Berikut beberapa olshop tas di Shopee yang bisa kami rekomendasikan buat kamu. Baca selegkapnya di link ini ya 5 Olshop Jual Tas Murah di Shopee. Untuk bekerja, ada banyak model handbag formal dari berbagai harga dari mulai harga yang murah dan terjangkau, hingga yang mahal. Buat kamu yang mencari handbag murah, bisa menyimak informasi buka halaman ini. Untuk tampilan yang casual saat jalan jalan atau traveling, bisa menggunakan tas ransel bergaya casual. Jika kamu membutuhkan rekomendasi tas ransel casual, baca artikel 4 Rekomendasi Tas Ransel Untuk Wanita yang Bergaya Casual. Buat kamu yang lebih memilih menggunakan fashion yang harganya terjangkau, cek olshop yang ada di halaman 5 olshop jual tas ransel wanita murah di Bandung. Kalau kamu termasuk wanita yang nyaman menggunakan tas ransel dalam beraktivitas, sepertinya tidak ada salahnya kamu mrmbaca informasi yang ada di tautan 5 Rekomendasi Tas Ransel Wanita Stylish Untuk Kerja. Agar lebih praktis saat traveling, kamu bisa membawa tas ransel mini untuk membawa barang barang yang sering digunakan dalam perjalanan. Cek artikel 5 rekomendasi tas ransel traveling wanita supaya penampilanmu saat traveling lebih modis dan kekinian. Agar tidak bosan dengan tas ransel kuliah yang itu itu aja, baca deh artikel 5 rekomendasi tas ransel kuliah wanita kekinian. Selain biar gak bosan, tampilanmu juga akan lebih modis dan kekinian saat kuliah.

Faddy 说:
2021年3月06日 20:56

Thank you for another great article. Where else could anyone get that kind of information in such a perfect way of writing? I have a presentation next week, and I am on the look for such information. 먹튀

no excuses runner 说:
2021年3月09日 17:47

Excellent .. Amazing .. I’ll bookmark your blog and take the feeds also…I’m happy to find so many useful info here in the post, we need work out more techniques in this regard, thanks for sharing. 먹튀검증업체

Faddy 说:
2021年3月14日 17:02

You have a real talent for writing unique content. I like how you think and the way you express your views in this article. I am impressed by your writing style a lot. Thanks for making my experience more beautiful. 먹튀검증사이트

Faddy 说:
2021年3月18日 14:56

This particular papers fabulous, and My spouse and I enjoy each of the perform that you have placed into this. I'm sure that you will be making a really useful place. I has been additionally pleased. Good perform! 꽁 머니 홍보방

Weight Loss 说:
2021年3月20日 23:49

Simple Moving Company established to provide stress free moving services. We are fully licensed and insured full service local and long distance moving company. Our goal is to provide excellent customer service, fast deliveries and successful relocation to all our customers. We know moving isn’t easy and a very stressful event and we make sure that you will have a SIMPLE move. To arrange movers, please contact us at your convenience. We look forward to meeting you soon. HEADQUARTER ADDRESS 1919 VINEBURN AVE, STE 04, LOS ANGELES, 90032 moving company los angeles

no excuses runner 说:
2021年3月21日 20:35

Affordable Pool Remodeling New Hampshire, Boston, All MA | Pool Plastering and Resurfacing Pool Renovation

Faddy 说:
2021年3月25日 20:20

Particular interviews furnish firsthand message on mart size, industry trends, ontogeny trends, capitalist landscape and outlook, etc. seo freelancer tools

Faddy 说:
2021年3月27日 19:43

If someone week i really ashen-haired not actually pretty, whether you will lite grope a present, thought to follow us to displays bursting with ends of the earth considerably? Inside the impeccant previous, sea ever have dried-up, my hubby and i only may very well be with all of you connected thousands of samsara. Onewheel

Weight Loss 说:
2021年3月31日 03:10

Faux leather or can be named Synthetic leather or Imitation leather or Artificial leather, There are 3 primary types of faux leather fabrics Faux Leather ViewPoint, Please visit our website to get the best & honest information for all kind of leathers.

no excuses runner 说:
2021年4月04日 16:22

I have added and shared your site to my social media accounts to send people back to your site because I am sure they will find it extremely helpful too. Onewheel Pint Accessories

no excuses runner 说:
2021年4月07日 19:56 If someone week i really ashen-haired not actually pretty, whether you will lite grope a present, thought to follow us to displays bursting with ends of the earth considerably? Inside the impeccant previous, sea ever have dried-up, my hubby and i only may very well be with all of you connected thousands of samsara. Managed IT Support near me Cheviot Hills Los Angeles, California
Weight Loss 说:
2021年4月09日 14:28

Sky Marketing strives to be Pakistan's biggest real estate developer ever, guaranteeing the highest international standards, prompt execution, and lifetime customer loyalty. With projects like park view city, islamabad.

melanin injections 说:
2021年4月12日 02:40

Buy Pharmacy grade drugs to boost stamina and enhance performance. Buy HGH, mens sexual health products, weight loss remedy, EPO and Clenbuterol Buy Online. melanin injections

Weight Loss 说:
2021年4月14日 01:31

Our goal is to facilitate your access to the largest global brands and attention to delivery, so you can devote yourself to managing your project مونين

no excuses runner 说:
2021年4月17日 13:53

Healing touch is a truly needed element to better mental health. With massage we can work out the tensions in the muscles that you tighten in anxious moments, and the aches that come from depression. Reiki Treatment

no excuses runner 说:
2021年4月20日 16:51

We have been selling potency drugs continuously since 2008. We are familiar with this industry not only from the side of the trends prevailing on the market, but above all from the biochemical and pharmaceutical side. Viagra

mpo slot 说:
2021年4月21日 22:52

I really appreciate this wonderful post that you have provided for us. I assure this would be beneficial for most of the people. mpo slot

Weight Loss 说:
2021年4月24日 00:27

We're a tech company developed by caterers for caterering, harnessing the power of social networking into catering. Corporate catering company Leicester

asdzxc 说:
2021年4月30日 03:48

Welcome to Altered Carbon's fan page where we connect with working dog enthusiasts and share our journey from puppy to adult using positive reinforcement to train black russian terriers to be protection dogs / guard dogs. Altered Carbon

HOVERBOARDS FOR SALE 说:
2021年5月02日 17:36

Save Up this Year - Get Hoverboards for Sale UK, The Only Company Providing Certified Hoverboards from British Design. HOVERBOARDS FOR SALE UK

Faddy 说:
2021年5月02日 19:38

Home Inspection Columbus Ohio by HC Inspectors - Home Inspection near me , Results Driven! Professional home inspectors We provide new construction, mold, radon, lead paint inspections and more! Please visit our website for Home and Commercial Property Inspection Services.

no excuses runner 说:
2021年5月04日 17:50

Fastag Online How to Apply Fastag in India and Everything you know about Fastag recharge , how to apply Fastag Online with banks. fastag login

asdzxc 说:
2021年5月08日 02:43

Bougie Moms love class and style and they will love the Itzy Ritzy Diaper Bag, Gender Neutral , tons of features and style galore. If you're a mom who isn't ready to give up on style and want the look of a chic bag combined with the function of a diaper bag, then this one's specially designed for you! itzy ritzy diaper bag

asdzxc 说:
2021年5月10日 02:05

All of our growers follow the strictest guidelines. No pesticides, long curing times and all strains are tested in house to ensure that you receive the highest quality. Marijuana for sale

weed for sale 说:
2021年5月11日 20:17

Just pure classic stuff from you here. I have never seen such a brilliantly written article in a long time. I am thankful to you that you produced this! weed for sale

dry eyes 说:
2021年5月12日 19:05

You make so many great points here that I read your article a couple of times. Your views are in accordance with my own for the most part. This is great content for your readers. <a href="https://eyedoctorcollinsville.com/2021/03/dry-eyes/">dry eyes</a>

dry eyes 说:
2021年5月12日 19:05

You make so many great points here that I read your article a couple of times. Your views are in accordance with my own for the most part. This is great content for your readers. dry eyes

no excuses runner 说:
2021年6月23日 17:11

Best New Bingo Sites 2021 A2Z Sister Site Free slots no deposit ​| The Best Place To Find Casinos & their Sister Sites, UK Largest Casino SisterSites ListChoose from A-Z catalogue with best offers. Please visit our website for more information and limited offers. Thank You.

click here 说:
2021年6月26日 18:47

ReelEmperor: Play Online Casino For Real Money In India. Competet against others and win every 4 hours.Get massive rewards every time you level up, Earn points for every spin and exchange them for bonuses and much more, click here ​​this site ​​​and sign up today to get welcome package for your first 3 deposits. Thank You click here

Website 说:
2021年6月27日 00:44

If you are looking for Orignal Seiko Men's and Women's watches Please click here to visit Benelli Jeweler Website. A center for watches, jewelry, repairs and gold purchasing. You will also find best quality of smartwatches.

Best Slots Sites 说:
2021年7月01日 19:09

Slots sites are the most popular search online, that is why we try to collect the Best Slots Sites ​here as a list for convenience over time.

asdzxc 说:
2021年7月13日 03:55

Dove for Sale | Buy Quality Bird Cages & The Best Dove Breeds, Shop Doves World™ for low prices on the best dove breeds and bird cages. Doves World™ has a wide selection from small and medium to large bird cages and ringneck doves for sale. Please visit our website ​for more info, Thank You.

Polaris 说:
2021年7月16日 13:39

The #1 trusted Polaris UTV by land owners, farmers, and hunters for over a decade. Polaris Ranger For Sale UK 0 Finance Available Full range available at Beckside Machinery Official Polaris Dealers UK. Beckside Machinery Ltd, registered as a limited company in England and Wales, Please visit our Website for more details. Thank You.

website 说:
2021年7月17日 18:37

Sign up and get 10% Off, BuffK 9® Dog Supplements specialize in natural vitamins and supplements for ALL dogs! Improved lean muscle, endurance, joint health and overall well being! Visit this website ​for natural & Best Dog Supplements & Vitamins. At BuffK-9® Dog Supplements we specialize in healthy, 100% safe, 100% natural, side-effect free supplements for ALL family dogs.

Hire a professional 说:
2021年7月24日 22:51

Looking an unusual gift to thank your customers or employees? Want a unique way to celebration a birthday, anniversary or other special occasion? It’s time to think outside the box and give one-of-a-kind experience – a virtual show by the Master of the Unexpected. Hire a professional magician for corporate event entertainment, Corporate Event Magician ,Wedding Party Entertainer, and more Doug Roy is a strolling magician. and event entertainer Hire a professional magician

virus 说:
2022年1月05日 20:20

I wanted to thank you for this excellent read!! I definitely loved every little bit of it. I have you bookmarked your site to check out the new stuff you post. dance classes for kids near me

virus 说:
2022年1月11日 18:18

I was looking at some of your posts on this website and I conceive this web site is really instructive! Keep putting up.. pubfilm

HGDFFH 说:
2022年1月11日 18:37

Super-Duper site! I am Loving it!! Will come back again, Im taking your feed also, Thanks. 0x0 0x0

virus 说:
2022年2月08日 18:35 Thanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for. buy pain pills online uk
. 카지노사이트 说:
2022年2月18日 01:22

nice post, keep up with this interesting work. It really is good to know that this topic is being covered also on this web site so cheers for taking time to discuss this! CBD treats for dogs

virus 说:
2022年3月05日 15:59

I read a article under the same title some time ago, but this articles quality is much, much better. How you do this.. Film Reviews

. 카지노사이트 说:
2022年4月10日 01:33

 Them can be found in a number of pressures along with seems with own internet websites. click this link

virus 说:
2022年4月21日 15:54

I definitely enjoying every little bit of it. It is a great website and nice share. I want to thank you. Good job! You guys do a great blog, and have some great contents. Keep up the good work. 먹튀검증커뮤니티

. 카지노사이트 说:
2022年4月24日 02:53

What is an outstanding post! “I’ll be back” (to read more of your content). Thanks for the nudge! Milieu vriendelijk woning bouwen

. 카지노사이트 说:
2022年4月27日 03:51

i was just browsing along and came upon your blog. just wanted to say good blog and this article really helped me. white label tokenization

. 카지노사이트 说:
2022年5月03日 01:46

We think that everyone deserves a chance at solid & secure authentication tools which includes privacy by default. That's why we created AuthGS™ We're proud to be one of the easiest authentication providers to integrate in your application, and we have a lot of security features waiting for you! build auth

. 카지노사이트 说:
2022年5月06日 20:41

You know your projects stand out of the herd. There is something special about them. It seems to me all of them are really brilliant! 출장안마

. 카지노사이트 说:
2022年9月08日 02:00

Thank you for some other informative blog. Where else could I get that type of information written in such an ideal means? I have a mission that I’m just now working on, and I have been at the look out for such information. Microsoft AZ-900 Dumps https://dumpstoday.com/az-900-dumps/


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter