linux后台执行命令crontab
2024-10-20 16:35:24
有如下几种方式:
crontab
at
&
nohup
1. crontab
定时执行任务
# crontab -e //编辑crontab配置文件
Select an editor. To change later, run 'select-editor'.
1. /bin/ed
2. /bin/nano <---- easiest
3. /usr/bin/emacs24
4. /usr/bin/vim.basic
5. /usr/bin/vim.tiny
Choose 1-5 [2]:
# crontab -l //查看crontab配置文件
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
5 * * * * ls
# crontab -r //删除所有调度任务
语法格式
分 | 小时 | 日 | 月 | 星期 | 命令 |
---|---|---|---|---|---|
0-59 | 0-23 | 1-31 | 1-12 | 0-6 | cmd |
特殊符号
*:所有数字
/:每
-:一个区间
,:多个数字
2. at
特定任务运行一次
# service atd status //查看atd服务
atd start/running, process 1350
# at now + 5 minutes //添加
warning: commands will be executed using /bin/sh
at> /home/a.out
at> ctrl+D
job 4 at Wed Apr 19 14:48:00 2017
时间 | 例子 | 说明 |
---|---|---|
Minute | at now + 5 minutes | 任务在5分钟后运行 |
Hour | at now + 1 hour | 任务在1小时后运行 |
Days | at now + 3 days | 任务在3天后运行 |
Weeks | at now + 2 weeks | 任务在两周后运行 |
Fixed | at midnight | 任务在午夜运行 |
Fixed | at 10:30pm | 任务在晚上10点30分 |
Fixed | at 23:59 12/31/2018 | 任务在2018年12月31号23点59分 |
# at -l //列出所有作业
1 Thu Apr 20 02:05:00 2017 a thomas
# at -r job //删除作业
Warning: deleting running job
3. &
在后台运行一个占用时间不长的任务
# jobs //查看后台运行任务
# fg //将后台运行任务调至前台
4. ctrl + z
将一个正在前台执行的命令放到后台,并且处于暂停状态
5. nohup
在后台运行一个命令,即使在用户退出时也不受影响
# nohup --help
Usage: nohup COMMAND [ARG]...
or: nohup OPTION
6. 查看当前终端的进程id
# echo $$
2602
最新文章
- 小兔JS教程(三)-- 彻底攻略JS回调函数
- ViewPager取消左右滑动切换功能
- angularjs结合d3js实现资源展示
- 移动端WEB开发备忘录
- canvas学习之制作动画
- 《第一行代码--Android》阅读笔记之数据持久化
- Android实现抽奖转盘
- 【JAVA - SSM】之MyBatis开发DAO
- 【SSH进阶之路】Hibernate映射——多对一单向关联映射(四)
- HDU2544-最短路(最短路模版题目)
- 利用JAVA API远程进行HDFS的相关操作
- FreeSql 新的八大骚功能,.NETCore 你必须晓得的 ORM
- icon图标库记录
- sql中遍历字符串
- 涂抹mysql笔记-搭建mysql高可用体系
- SpringBoot入门篇--热部署
- RestTemplate--解决中文乱码
- jquery-alert对话框
- linux性能评估与分析工具---CPU篇
- 字符串模式匹配算法--BF和KMP详解
热门文章
- pip 安装指定版本
- ES6深入浅出-9 Promise-1.回调与回调地狱
- 123457123456#0#----com.DoraGame.AiMiYu20--前拼后广--caimi-doraX
- Elasticsearch技术解析与实战 PDF (内含目录)
- Spring MVC 为控制器添加通知与处理异常
- c# vs2010 连接access数据库(转)
- 【ARTS】01_40_左耳听风-201900812~201900818
- iOS label出现异常黑色问题
- NAT的配置
- LeetCode 378. 有序矩阵中第K小的元素(Kth Smallest Element in a Sorted Matrix) 13