使用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
相关推荐
Calebbbbb15 分钟前
Ubuntu 24.04 + Android 15 (AOSP) 环境搭建与源码同步完整指南
android·linux·ubuntu
STCNXPARM24 分钟前
Linux PCI/PCIe子系统深度剖析
linux·运维·服务器·pci/pcie
郝学胜-神的一滴28 分钟前
深入理解Linux套接字(Socket)编程:从原理到实践
linux·服务器·开发语言·网络·c++·程序人生·算法
坐怀不乱杯魂1 小时前
Linux - 线程
linux·c++
EverydayJoy^v^1 小时前
RH134学习进程——八.管理存储堆栈
linux·运维·服务器
爱编码的傅同学1 小时前
【线程同步】信号量与环形队列的生产消费模型
linux·windows·ubuntu·centos
Nick.Q2 小时前
CentOS 8 离线安装beyond compare
linux·centos
鹿鸣天涯2 小时前
openEuler学习笔记1-openEuler前世今生
linux·openeuler
pwn蒸鱼2 小时前
buuctf中的mrctf2020_shellcode
linux·安全
夕除2 小时前
java--1
linux·运维·服务器