1.写脚本

最简单的 写如下代码

#!/bin/sh

A

B

C

1.每个命令之间用;隔开

说明:各命令的执行给果,不会影响其它命令的执行。换句话说,各个命令都会执行,

但不保证每个命令都执行成功。

2.每个命令之间用&&隔开

说明:若前面的命令执行成功,才会去执行后面的命令。这样可以保证所有的命令执行完毕后,执行过程都是成功的。

例如:cat /etc/redhat-release && yum -y update && yum list | grep installed > installed.txt 三个命令

3.每个命令之间用||隔开

说明:||是或的意思,只有前面的命令执行失败后才去执行下一条命令,直到执行成功

一条命令为止。

保存为test.sh

然后添加执行权限chmod +x test.sh

然后执行该脚本./test.sh

{EG:#!/bin/bash

echo “I love you !” >> /home/luogen30/Desktop/t.txt

}

2.编辑定时任务

crontab –e

30 7 * * * root /root/shell/rule1.sh >> /root/shell/filename.log 2>&1

(执行脚本script.sh时将错误输出2以及标准输出1都一起以附加写方式导入logfile文件。

即使多次执行脚本,之前的log也仍然存在。)

为每天7点半执行,并且导入日志到后面

/etc/init.d/cron start //启动服务

/etc/init.d/cron stop //关闭服务

/etc/init.d/cron restart //重启服务

/etc/init.d/cron reload //重新载入配置

/etc/init.d/cron status //查看服务状态

查看已经编写的定时任务:

在命令终端输入:crontab -l

在命令终端 执行:

cron restart重启定时任务.

service crond restart

摘录

crontab文件的格式:

minute hour day month weekday username command

minute:分,值为0-59

hour:小时,值为1-23

day:天,值为1-31

month:月,值为1-12

weekday:星期,值为0-6(0代表星期天,1代表星期一,以此类推)

username:要执行程序的用户,一般设置为root

command:要执行的程序路径(设置为绝对路径)例如:/home/www.osyunwei.com/osyunwei.sh

附:crontab规则详细实例

1、每天6:00执行

0 6 * * * root /home/www.osyunwei.com/osyunwei.sh

2、每周六凌晨4:00执行

0 4 * * 6 root /home/www.osyunwei.com/osyunwei.sh

3、每周六凌晨4:05执行

5 4 * * 6 root /home/www.osyunwei.com/osyunwei.sh

4、每周六凌晨4:15执行

15 4 * * 6 root /home/www.osyunwei.com/osyunwei.sh

5、每周六凌晨4:25执行

25 4 * * 6 root /home/www.osyunwei.com/osyunwei.sh

6、每周六凌晨4:35执行

35 4 * * 6 root /home/www.osyunwei.com/osyunwei.sh

7、每周六凌晨5:00执行

5 * * 6 root /home/www.osyunwei.com/osyunwei.sh

8、每天8:40执行

40 8 * * * root /home/www.osyunwei.com/osyunwei.sh

9、每天8:30执行

30 8 * * * root /home/www.osyunwei.com/osyunwei.sh

10、每周一到周五的11:41开始,每隔10分钟执行一次

41,51 11 * * 1-5 root /home/www.osyunwei.com/osyunwei.sh

1-59/10 12-23 * * 1-5 root /home/www.osyunwei.com/osyunwei.sh

11、在每天的10:31开始,每隔2小时重复一次

31 10-23/2 * * * root /home/www.osyunwei.com/osyunwei.sh

12、每天15:00执行

0 15 * * * root /home/www.osyunwei.com/osyunwei.sh

13、每天的10:30开始,每隔2小时重复一次

30 10-23/2 * * * root /home/www.osyunwei.com/osyunwei.sh

14、每天15:30执行

30 15 * * * root /home/www.osyunwei.com/osyunwei.sh

15、每天17:50执行

50 17 * * * root /home/www.osyunwei.com/osyunwei.sh

16、每天8:00执行

0 8 * * * root /home/www.osyunwei.com/osyunwei.sh

17、每天18:00执行

0 18 * * * root /home/www.osyunwei.com/osyunwei.sh

18、每天8:30执行

30 8 * * * root /home/www.osyunwei.com/osyunwei.sh

19、每天20:30

30 20 * * * root /home/www.osyunwei.com/osyunwei.sh

20、每周一到周五2:00

0 2 * * 1-5 root /home/www.osyunwei.com/osyunwei.sh

21、每周一到周五9:30

30 9 * * 1-5 root /home/www.osyunwei.com/osyunwei.sh

22、每周一到周五8:00,每周一到周五9:00

0 8,9 * * 1-5 root /home/www.osyunwei.com/osyunwei.sh

23、每天23:59

59 23 * * * root /home/www.osyunwei.com/osyunwei.sh

24、每周六23:59

59 23 * * 6 root /home/www.osyunwei.com/osyunwei.sh

25、每天0:30

30 0 * * * root /home/www.osyunwei.com/osyunwei.sh

26、每周一到周五9:25到11:35之间、13:00到15:00之间,每隔10分钟运行一次

25,35,45,55 9 * * 1-5 root /home/www.osyunwei.com/osyunwei.sh

5-59/10 10 * * 1-5 root /home/www.osyunwei.com/osyunwei.sh

5,15,25,35 11 * * 1-5 root /home/www.osyunwei.com/osyunwei.sh

*/10 13-15 * * 1-5 root /home/www.osyunwei.com/osyunwei.sh

27、每周一到周五8:30、8:50、9:30、10:00、10:30、11:00、11:30、13:30、14:00、14:30、5:00分别执行一次

30,50 8 * * 1-5 root /home/www.osyunwei.com/osyunwei.sh

30 9 * * 1-5 root /home/www.osyunwei.com/osyunwei.sh

*/30 10-11 * * 1-5 root /home/www.osyunwei.com/osyunwei.sh

30 13 * * 1-5 root /home/www.osyunwei.com/osyunwei.sh

0,30 14-15 * * 1-5 root /home/www.osyunwei.com/osyunwei.sh

28、每天23:50执行

50 23 * * * root /home/www.osyunwei.com/osyunwei.sh

29、每天10:00、16:00执行

0 10,16 * * * root /home/www.osyunwei.com/osyunwei.sh

30、每天5:30执行

30 5 * * * root /home/www.osyunwei.com/osyunwei.sh

31、每周一到周五9:30执行

30 9 * * 1-5 root /home/www.osyunwei.com/osyunwei.sh

32、每周一到周五13:00执行

0 13 * * 1-5 root /home/www.osyunwei.com/osyunwei.sh

33、每天7:51执行

51 7 * * * root /home/www.osyunwei.com/osyunwei.sh

34、每天7:53、12:40分别执行一次

53 7 * * * root /home/www.osyunwei.com/osyunwei.sh

40 12 * * * root /home/www.osyunwei.com/osyunwei.sh

35、每天7:55执行

55 7 * * * root /home/www.osyunwei.com/osyunwei.sh

36、每天8:10、16:00、20:00分别执行一次

10 8 * * * root /home/www.osyunwei.com/osyunwei.sh

0 16 * * * root /home/www.osyunwei.com/osyunwei.sh

0 20 * * * root /home/www.osyunwei.com/osyunwei.sh

37、每天7:57、8:00分别执行一次

57 7 * * * root /home/www.osyunwei.com/osyunwei.sh

0 8 * * * root /home/www.osyunwei.com/osyunwei.sh

这里放置我之前服务器运行的一些计划任务

05 13 * * * /scripts/test.sh >/opt/crontablog.txt

30 06 * * * /shell/end.sh >/opt/crontablog.txt

备注:有几次我计划任务上写root用户,却发现执行不了

linux计划任务执行日志,linux中centos制定计划任务执行命令并且输出日志相关推荐

  1. vs2017 linux so导出函数,将Visual Studio 2017中的Assembly和C ++与命令行和输出相结合

    我正在尝试将这些语言结合起来用于测试目的.有没有人知道为什么,在构建项目后,当.asm文件在源文件夹中时,无法找到clear函数.下面显示的以下图像应该解释我的要求,我将进一步编辑. .586 ;Ta ...

  2. linux上的字典和数组中,centos安装词典——图形界面的和命令行

    stardict词典:这个词典好像在图形界面下用的,在命令行界面下不能用(stardict词典包可到https://pkgs.org/查找). 安装方法: 在/etc/yum.repos.d/目录下创 ...

  3. android执行.sh,android中调整cpu频率以及执行sh文件简单记录

    注意:以下操作环境为win7 + android 5. 要想在android设备中执行sh文件,有2种方式. 一.一种是执行 adb  shell(注意 test.sh文件这里是放在跟adb工具一样的 ...

  4. java继承父类执行顺序_java中子类继承父类程序执行顺序问题

    Java中,new一个类的对象,类里面的静态代码块.非静态代码.无参构造方法.有参构造方法.类的一般方法等部分,它们的执行顺序相对来说比较简单,用程序也很容易验证.比如新建一个测试父类. public ...

  5. red hat linux怎么运行,Red Hat Linux中自动运行程序

    1.开机启动时自动运行程序 Linux加载后, 它将初始化硬件和设备驱动, 然后运行第一个进程init.init根据配置文件继续引导过程,启动其它进程.通常情况下,修改放置在 /etc/rc或 /et ...

  6. linux 关机 日志,centos7 异常关机了,怎么查看系统的异常日志?

    centos7 异常关机了,怎么查看系统的异常日志? crash中也没有dump的文件. 这是messages日志: Feb 26 11:14:03 moon systemd-logind: Remo ...

  7. linux 内核模型,The Linux Kernel Device Model - Overview -- Linux 内核设备模型概述

    --------------------------------------------------------------------------------------------------- ...

  8. Linux jq 、vim以及LInux集群安装miniconda并配置虚拟环境(笔记)

    https://github.com/QInzhengk/Math-Model-and-Machine-Learning Linux jq .vim以及LInux集群安装miniconda并配置虚拟环 ...

  9. find linux 目录深度_把 Linux 上的文件列表和排序玩出花来

    Linux 命令可以提供文件的详细信息,也可以自定义显示的文件列表,甚至可以深入到文件系统的目录中,只要你愿意看. • 来源:linux.cn • 作者:Sandra Henry-stocker • ...

最新文章

  1. 快速上手的Glide4.x教程
  2. shell-init: error
  3. 【算法漫画】什么是红黑树?(下篇)
  4. C++类分号(;)问题
  5. python文本聚类分析_python机器学习kmeans算法——对文本进行聚类分析
  6. 显示器分辨率一直跳_2020如何选择适合自己的显示器?小白选购电脑显示器必看!...
  7. 一阶电路中的时间常数_你知道RC电路和RL电路中时间常数的来源么?
  8. 推荐一款代码神器,代码量至少省一半! 1
  9. 迷失第一季/全集Lost 1迅雷下载
  10. 旅程落幕!网易相册将停止运营 这里有你的回忆吗?
  11. mysql创建用户和远程登录授权
  12. 【软考】程序设计语言复习指南
  13. cad面积累计lisp怎么用_CAD连续面积标注lisp插件
  14. Strassen矩阵乘法
  15. 盘古搜索:上市是既定策略 寻求股权多元化
  16. 教你如何使用github+jsDelivr搭建免费图床
  17. Unity漫反射 镜面反射
  18. python错误提示未定义tn_python错误提示未定义tn_未找到Python方法,但在类中定义
  19. 【机器学习】决策树(Decision Tree)
  20. linux网络之怪现象一--接网线启动网络不通,不接网线启动再插线网络通

热门文章

  1. 使用代码设置Item级的权限(权限总结1)
  2. [ASP,VB] - 利用ASP调用API COM接口实现开关机
  3. webpack入门进阶调优第一章
  4. javaScript第七天(1)
  5. MVC开发中的常见错误-04-“System.NullReferenceException”类型的异常在 BBFJ.OA.WebApp.dll 中发生,但未在用户代码中进行处理...
  6. caffe 中的一些参数介绍
  7. ios7开发学习笔记-包括c oc 和ios介绍
  8. 【创业】创业团队的那些事(二)
  9. Windows和Linux如何使用Java代码实现关闭进程
  10. “智云大咖秀”:大咖摄影师谈惊艳亮相的“大咖级”设备