第48天-学习 crontab 工作排程

今天进度 鸟哥私房菜 - 第十五章、例行性工作排程(crontab)

我在 Crontab.guru - The cron schedule expression editor 练习 crontab 表达式

corntab 的规则如下:

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed

例子 : 每一分钟发讯息给大家

  1. crontab -e 开启编辑
  2. 输入 1 * * * * wall 'HI IT帮'
  3. crontab -l 验证是否有列入排程
  4. 没有启用,可以尝试 systemctl restart crond 重启服务
test@test:~$ crontab -e # 开启编辑

*/1 * * * * wall 'HI IT帮' # 输入保存

crontab: installing new crontab # 显示正在安装

test@test:~$ crontab -l # 显示目前运行的
*/1 * * * * wall 'HI IT帮'

test@test:~$ systemctl restart crond
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to restart 'crond.service'.
Authenticating as: test
Password: 
==== AUTHENTICATION COMPLETE ===
Failed to restart crond.service: Unit crond.service not found.

# 等一分钟後
Broadcast message from test@test (somewhere) (Wed Oct 21 01:01:01 2020):              
HI IT帮

例子 : 开机後创建一个档案

@reboot	touch 路径

测试

test@test:~$ crontab -e
@reboot	touch /home/test/start.txt
test@test:~$ reboot
test@test:~$ ls
start.txt

遇到问题

想要获取当下绝对路径

pwd

测试

test@test:~$ pwd
/home/test

我参考 Display the Path of Your Current Directory | Navigating Your File System in Linux | InformIT


每日一句 :

一天一Linux,头发远离我 ~


<<:  35.Local Storage

>>:  [Golang]GOROOT与GOPATH的说明-心智图

30天零负担轻松学会制作APP介面及设计【DAY 11】

大家好,我是YIYI,今天我要利用MARVEL将前面三个介面做出连结。 制作介面连结 首先,先进入昨...

# Day9--老爸,我可以继承你的家产,但我不想长得太像你

引述自100Days of Swift-Class inheritance: The second ...

Vue.js 从零开始:Hoisting , undefined,not defined

续上一篇文章,写到後面还有一些观念没有讲得很清楚,像是var有Hoisting的特性,coding的...

自我笔记 - django 系列 [模型基础篇]

django - Models 本篇说明 django 使用资料库的方式 以及应用面会使用到的多资料...

DAY22 这边先帮你上一个按钮喔~(四)

「欸!?阿按了这个按钮怎麽没反应阿?」 这是我妈最常问我的问题,大部分情况都是她遥控器忘记装电池。 ...