有如下几种方式:

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的更多相关文章

  1. Linux后台执行命令:&和nohup nohup和&后台运行,进程查看及终止

    nohup和&后台运行,进程查看及终止   阅读目录 nohup和&后台运行,进程查看及终止 1.nohup 2.& 3.nohup和&的区别 &:是指在后台运 ...

  2. linux后台执行命令&

    当在前台运行某个作业时,终端被该作业占据:而在后台运行作业时,它不会占据终端.可以使用&命令把作业放到后台执行. 如:30 2 * * * /data/app/scripts/hotbacku ...

  3. linux后台执行命令:&和nohup

    当我们在终端或控制台工作时,可能不希望由于运行一个作业而占住了屏幕,因为可能还有更重要的事情要做,比如阅读电子邮件.对于密集访问磁盘的进程,我们更希望它能够在每天的非负荷高峰时间段运行(例如凌晨).为 ...

  4. 【liunx】linux后台执行命令:&和nohup

    当我们在终端或控制台工作时,可能不希望由于运行一个作业而占住了屏幕,因为可能还有更重要的事情要做,比如阅读电子邮件.对于密集访问磁盘的进程,我们更希望它能够在每天的非负荷高峰时间段运行(例如凌晨).为 ...

  5. linux后台执行命令:&与nohup的用法

    & 这种方法很简单,就是在命令之后加个“&”符号就可以了,如下: ./test & 这样一来,test程序就在后台运行了.但是,这样处理还不够,因为这样做虽然程序是在后台运行了 ...

  6. linux 后台执行命令

    本文主要内容: 1. 设置ctontab文件,并用它来提交作业. 2. 使用at命令来提交作业. 3. 在后台提交作业. 4. 使用nohup命令提交作业. 名词解释: cron 系统调度进程.可以使 ...

  7. [转帖]Linux后端执行命令的方法

    Linux 后台执行命令的方法 http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=4241330&fromuid=212883 ...

  8. Debian的定时执行命令Crontab

    转载:http://i.592.net/?post=276 Debian的定时执行命令Crontab,这个相当于Windows的计划任务 想要让Debian定时执行命令就得靠crontab了!     ...

  9. 在linux后台执行脚本

    1. 使用&符号在后台执行命令 你可以在Linux命令或者脚本后面增加&符号,从而使命令或脚本在后台执行,例如:. $ ./my-shell-script.sh & 2. 使用 ...

随机推荐

  1. IFC构件位置数据与revit模型中对应构件位置数据对比

    IFC构件位置数据与revit模型中对应构件位置数据对比

  2. 【DataBase】H2 DateBase的简单使用

    H2介绍 H2是一个开源的嵌入式数据库引擎,采用java语言编写,不受平台的限制,同时H2提供了一个十分方便的web控制台用于操作和管理数据库内容. H2还提供兼容模式,可以兼容一些主流的数据库,因此 ...

  3. 利用postman生成各种编程语言的代码

    原文来源:https://learning.getpostman.com/docs/postman/sending_api_requests/generate_code_snippets/ 在Post ...

  4. SAP RFC和BAPI

    RFC和BAPI都是SAP提供的接口技术.RFC全称Remote Function Call,就是允许远程调用的函数模块. BAPI则是基于RFC的新技术,全称Business Application ...

  5. Flink统计当日的UV、PV

    Flink 统计当日的UV.PV 测试环境: flink 1.7.2 1.数据流程 a.模拟数据生成,发送到kafka(json 格式) b.flink 读取数据,count c. 输出数据到kafk ...

  6. Redis应用场景梳理

    缓存 作为Key-Value形态的内存数据库,Redis 最先会被想到的应用场景便是作为数据缓存.而使用 Redis 缓存数据非常简单,只需要通过string类型将序列化后的对象存起来即可,不过也有一 ...

  7. (十)进度条媒体对象和 Well 组件

    一.Well 组件 有 lg 和 sm 两种可选值 <div class="well well-lg"> Bootstrap </div> 二.进度条组件 ...

  8. k8s版jenkins--master/slave模式实现CI/CD---带solo开源博客项目--带maven、djk、git工具

    k8s环境: 192.168.0.91 master 192.168.0.92 node 192.168.0.96 gitlab 192.168.0.98 harbor k8s集群安装请参照:http ...

  9. 什么时候该用readfile() , fread(), file_get_contents(), fgets()?

    fread() 和 readfile() fread() 最大一次性能读取 8k长度的字节数,所以不能一次性读取大文件去作下载. 优势在于,操作更加灵活,每次读取指定字节的内容,用于下载时方便控制服务 ...

  10. js 判断字符串是否为JSON格式

    function isJSON(str) { if (typeof str == 'string') { try { var obj=JSON.parse(str); if(typeof obj == ...