使用crontab创建定制化定时器任务(Linux/Ubuntu)

使用crontab创建定制化定时器任务(Linux/Ubuntu)

官网信息

crontab.guru/

查看使用案例:

点击examples

实践操作

help

python 复制代码
crontab -h
crontab: invalid option -- 'h'
crontab: usage error: unrecognized option
usage:	crontab [-u user] file
	crontab [ -u user ] [ -i ] { -e | -l | -r }
		(default operation is replace, per 1003.2)
	-e	(edit user's crontab)
	-l	(list user's crontab)
	-r	(delete user's crontab)
	-i	(prompt before deleting user's crontab)

set task

需求:每5分钟保存ifconfig信息

  • 启动编辑

    crontab -e

  • 配置

  • Ctrl+O保存

  • Ctrl+X退出

  • 查看是否配置成功

    复制代码
    crontab -l

总结

每分钟执行一次:

shell 复制代码
* * * * * * python pythonScript.py

每5分钟执行一次:

shell 复制代码
*/5 * * * * /bin/sh xxxx/xxxx.sh

每天执行一次:

shell 复制代码
0 0 * * * /bin/sh xxxx/xxxx.sh

可以根据需要,将所有需要执行的命令写在一个sh脚本中,然后执行。

shell 复制代码
*/1 * * * * /bin/sh xxxx/task_every_minute.sh
*/5 * * * * /bin/sh xxxx/task_every_5_minute.sh
0 * * * *   /bin/sh xxxx/task_every_60_minute.sh
0 0 * * *   /bin/sh xxxx/task_every_day.sh
0 0 * * 0   /bin/sh xxxx/task_every_week.sh
0 0 1 * *   /bin/sh xxxx/task_every_month.sh
相关推荐
orion5720 小时前
Missing Semester Class1:course overview and introduction of shell
linux
用户120487221611 天前
Linux驱动编译与加载
linux·嵌入式
用户805533698031 天前
Input 子系统架构:Core、Handler、Driver 三层是怎么协作的
linux·嵌入式
用户805533698031 天前
RK-Forge外设系列开篇 - 把板子从「能启动」变成「能用」:Ethernet/SPI/MMC 三个纯接线外设
linux·github·嵌入式
七歌杜金房2 天前
我终于又有了自己的 Linux 电脑
linux·debian·mac
tntxia3 天前
linux curl命令详解_curl详解
linux
扛枪的书生3 天前
Linux 网络管理器用法速查
linux
顺风尿一寸3 天前
Java Socket 内核之旅:从 SocketChannel.read() 到 tcp_recvmsg 与 epoll 的完整调用链路
linux
XIAOHEZIcode3 天前
Ubuntu 终端美化全栈指南:Bash 到 Kitty 踩坑实录
linux·ubuntu·命令行
唐青枫3 天前
别再只会用 cron:Linux systemd Timer 定时任务实战详解
linux