Code Monkey home page Code Monkey logo

Comments (1)

hehongwei44 avatar hehongwei44 commented on June 16, 2024

我们就来搭配几个例子练习看看吧!底下的案例请实际用 dmtsai 这个身份作看看喔!后续的动作才能够搭配起来!

例题:

假若你的女朋友生日是 5 月 2 日,你想要在 5 月 1 日的 23:59 发一封信给他,这封信的内容已经写在 /home/dmtsai/lover.txt 内了,该如何进行?

答:
直接下达 crontab -e 之后,编辑成为:

59 23 1 5 * mail kiki < /home/dmtsai/lover.txt

那样的话,每年 kiki 都会收到你的这封信喔!(当然啰,信的内容就要每年变一变啦!)

再来

例题:

假如每五分钟需要执行 /home/dmtsai/test.sh 一次,又该如何?

答:

同样使用 crontab -e 进入编辑:

*/5 * * * * /home/dmtsai/test.sh

那个 crontab 每个用户都只有一个文件存在,就是在 /var/spool/cron 里面啊! 还有建议您:‘执行命令时,最好使用绝对路径,这样比较不会找不到执行文件!’

例题:

假如你每星期六都与朋友有约,那么想要每个星期五下午 4:30 告诉你朋友星期六的约会不要忘记,则:
答:

还是使用 crontab -e 啊!

30 16 * * 5 mail [email protected] < /home/dmtsai/friend.txt

真的是很简单吧!呵呵!那么,该如何查询使用者目前的 crontab 内容呢?我们可以这样来看看:

[dmtsai@www ~]$ crontab -l
59 23 1 5 * mail kiki < /home/dmtsai/lover.txt
*/5 * * * * /home/dmtsai/test.sh
30 16 * * 5 mail [email protected] < /home/dmtsai/friend.txt

# 注意,若仅想要移除一项工作而已的话,必须要用 crontab -e 去编辑~
# 如果想要全部的工作都移除,才使用 crontab -r 喔!
[dmtsai@www ~]$ crontab -r
[dmtsai@www ~]$ crontab -l
no crontab for dmtsai

看到了吗? crontab ‘整个内容都不见了!’所以请注意:‘如果只是要删除某个 crontab 的工作项目,那么请使用 crontab -e 来重新编辑即可!’如果使用 -r 的参数,是会将所有的 crontab 资料内容都删掉的!千万注意了!

from my-blog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.