linux后台执行命令crontab
有如下几种方式:
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
linux后台执行命令crontab的更多相关文章
- Linux后台执行命令:&和nohup nohup和&后台运行,进程查看及终止
nohup和&后台运行,进程查看及终止 阅读目录 nohup和&后台运行,进程查看及终止 1.nohup 2.& 3.nohup和&的区别 &:是指在后台运 ...
- linux后台执行命令&
当在前台运行某个作业时,终端被该作业占据:而在后台运行作业时,它不会占据终端.可以使用&命令把作业放到后台执行. 如:30 2 * * * /data/app/scripts/hotbacku ...
- linux后台执行命令:&和nohup
当我们在终端或控制台工作时,可能不希望由于运行一个作业而占住了屏幕,因为可能还有更重要的事情要做,比如阅读电子邮件.对于密集访问磁盘的进程,我们更希望它能够在每天的非负荷高峰时间段运行(例如凌晨).为 ...
- 【liunx】linux后台执行命令:&和nohup
当我们在终端或控制台工作时,可能不希望由于运行一个作业而占住了屏幕,因为可能还有更重要的事情要做,比如阅读电子邮件.对于密集访问磁盘的进程,我们更希望它能够在每天的非负荷高峰时间段运行(例如凌晨).为 ...
- linux后台执行命令:&与nohup的用法
& 这种方法很简单,就是在命令之后加个“&”符号就可以了,如下: ./test & 这样一来,test程序就在后台运行了.但是,这样处理还不够,因为这样做虽然程序是在后台运行了 ...
- linux 后台执行命令
本文主要内容: 1. 设置ctontab文件,并用它来提交作业. 2. 使用at命令来提交作业. 3. 在后台提交作业. 4. 使用nohup命令提交作业. 名词解释: cron 系统调度进程.可以使 ...
- [转帖]Linux后端执行命令的方法
Linux 后台执行命令的方法 http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=4241330&fromuid=212883 ...
- Debian的定时执行命令Crontab
转载:http://i.592.net/?post=276 Debian的定时执行命令Crontab,这个相当于Windows的计划任务 想要让Debian定时执行命令就得靠crontab了! ...
- 在linux后台执行脚本
1. 使用&符号在后台执行命令 你可以在Linux命令或者脚本后面增加&符号,从而使命令或脚本在后台执行,例如:. $ ./my-shell-script.sh & 2. 使用 ...
随机推荐
- Spring5源码分析之启动类的相关接口和注解
一些基础但是核心的知识总结: Spring Boot项目启动的时候需要加@Configuration. @ComponentScan @Configuration + @Bean 把第三方jar包注入 ...
- Python3实战——爬虫入门
一.安装库 使用conda安装: conda install requests 如果出现解析环境问题,需要激活conda环境: https://www.cnblogs.com/jdemarryme/p ...
- 深入学习c++--智能指针(三) unique_ptr
1. 几种智能指针 1. auto_ptr: c++11中推荐不使用他(放弃) 2. shared_ptr: 拥有共享对象所有权语义的智能指针 3. unique_ptr: 拥有独有对象所有权语义的智 ...
- ES6深入浅出-6 ES 6 模块-1.模块化速学
把模块先默认认为是豆腐块 为什么前端需要模块? 没有模块的方式 预览这个html页面 一共200行js代码 前100行在做一件事 ,另外100行在做另一件事,这样就是两个模块 main.js来 ...
- java 时间的原生操作和工具类操作
package com.xc.test.dateoperation; import org.apache.commons.lang3.time.DateFormatUtils; import org. ...
- Git 和 SVN 存储方式的差异对比
Git git 对于一个文件的修改存储的是一个快照,就是说针对文件1,修改之后,生成文件2,文件2中包含文件的1的内容,如果当文件1不存在,版本回退也就不管用了. SVN SVN 存储的是对文件的差异 ...
- lua . 命令收集
io.popen()## 原型:io.popen ([prog [, mode]]) 解释:在额外的进程中启动程序prog,并返回用于prog的文件句柄.通俗的来说就是使用这个函数可以调用一个命令(程 ...
- htm5 css学习笔记整理
点击链接后退页面: <a href="javascript:history.go(-1)">回到上一个网页</a> ——修改placeholder提示的样式 ...
- JVM(四) 垃圾回收
1. 堆内存结构 Java堆从GC的角度可以细分为:新生代(Eden区.From Survivor区和To Survivor区)和老年代. 1.1 新生代 新生代是用来存放新生的对象.一般占据堆的1/ ...
- [ERROR] /D:/IDEA文件/travel/src/main/java/cn/itcast/travel/util/MailUtils.java:[1,1] 非法字符: '\ufeff'
报错: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (defau ...