1、查看root用户身份下正常运行的定时任务

crontab -l -u XXX 列出XXX用户的所有定时任务,如有没有会提示 no crontab for XXX
列出所有的用户:
cat /etc/passwd |cut -f 1 -d : 2、编写定时任务脚本xxx.sh:
#/bin/bash

set -x

srcdir=/cgdl/local-svn/rpm-svn/transplant-apps/v2./desktop-x86/
destdir=/cgdl/desktop-repos/v2./unstable/desktop-x86/third-part/ cd $srcdir
svn update
rsync -avz --delete $srcdir $destdir if [ ! -d $destdir/repodata ];then
createrepo_c --workers .
else
createrepo_c --workers --update $destdir
fi logdir=/var/log/
logfile=update_third-part_repo.log
cd $logdir
if [ ! -f "$logfile" ];then
touch $logfile
echo `date` > $logdir/$logfile
else
echo `date` >> $logdir/$logfile
fi

其中logdir部分是为了验证定时任务是否实际执行,每执行一次,就会向一个日志文件中追加日期信息;

3、将定时脚本搬移至/etc/crontab中

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root # For details see man crontabs # Example of job definition:
# .---------------- minute ( - )
# | .------------- hour ( - )
# | | .---------- day of month ( - )
# | | | .------- month ( - ) OR jan,feb,mar,apr ...
# | | | | .---- day of week ( - ) (Sunday= or ) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed * * * * /bin/sh /usr/local/bin/xxx.sh

4、重新启动定时任务

systemctl restart crond.service

5、查看定时任务执行状态

systemctl status crond
可以根据输出具体信息判断定时任务的是否正常执行,如果出现”bad command“说明,/etc/crotab脚本格式书写有问题(前提是定时脚本手工执行无问题哈);

linux中的定时任务创建的更多相关文章

  1. linux 中的定时任务crontab使用方法

    linux 中的定时任务crontab使用方法: 切换到root用户,sudo su root (可以设置成不需要输入密码) sudo su - (需要输入当前帐号的密码才能进入.) crontab ...

  2. linux中动态链接库的创建与使用

    LINUX系统中动态链接库的创建与使用 http://www.cnblogs.com/ardar/articles/357321.html 正常C源文件编写,编译时-shared即可得到SO, gcc ...

  3. linux中一次创建多个目录

    linux中创建目录当然使用命令工具mkdir == (make directory),联想记忆法能让你记得牢固. 如果你要创建几个目录,例如:dir1目录,dir2目录,dir3目录可以这样 mkd ...

  4. Linux中利用crontab创建计划任务

    在linux中启动crontab服务: /etc/init.d/crond  start crontab的命令格式 crontab -l   显示当前的crontab 文件(默认编写的crontab文 ...

  5. linux中执行定时任务对oracle备份(crontab命令)

    执行定时任务对oracle表数据备份: 1.创建sh脚本 [oracle@localhost ~]$ vi bak.sh 2.添加脚本内容 #!/bin/bash #:本脚本自动备份7天的数据库,每次 ...

  6. Linux中的定时任务简单操作实例

    今天,我怀着一颗感恩的心,写了一个小小的定时任务,细想还是写个简单的例子吧,希望能帮到你! 首先我在/usr/local/文件夹下创建了一个文件,hah.sh文件 在hah.sh里面编写shell脚本 ...

  7. linux中Cron定时任务系统命令详解

    分类:Linux VPS教程 作者:阿川 发布时间:October 13, 2011 有很多同学在购买VPS之后,需要用到计划任务.但是又对计划任务不太了解,所以.今天我们的帮助中心主要是给大家提供一 ...

  8. Linux中的定时任务at、crontab

    at at命令可以用来在某一时段执行一次任务,只会执行一次,不会重复执行. at命令是由atd服务来控制的,使用之前先查看atd服务是否正常: $ /etc/init.d/atd status * a ...

  9. Linux中crontab定时任务

    crontab安装(centOS) yum -y install vixie-cron crontab语法(计划任务) crontab [-u user] file crontab [-u user] ...

随机推荐

  1. 吴裕雄 python 机器学习-KNN(2)

    import matplotlib import numpy as np import matplotlib.pyplot as plt from matplotlib.patches import ...

  2. LisView控件

    用LisView控件在窗体中创建一个表,设置一个按钮,点击按钮, 将数据库中的表在这个控件中显示(LisView控件中表格式列名与数据库中一致) 首先使用控件将表的每一列创建好,加入一个按钮,如图,现 ...

  3. 魅族手机USB调试无法打开、log无法打印

    MEIZU 在打开usb调试允许时,总提示:because an app is oobscuring a premision request, Setting can't verify your re ...

  4. CentOS7 安装 GitLab

    虽然GitHub已经很好了,但是我们必须联上公网才可以使用并且如果不付费的话,你的代码在网上就是公开的!但是在企业环境中,我们公司的代码不希望被公开并且也不想付费给GitHub,这时怎么办呢?我们可以 ...

  5. java 反编译工具

    (1)点击进入>>   https://jingyan.baidu.com/article/3f16e003c857082590c1036f.html (备注:如果以上链接的资源不能下载, ...

  6. Android Studio 插件-Android Styler 的使用 (转)

    作用:把 xml文件 转为 style 截图保留 使用方法 使用方法:选中xml代码 按下 Ctrl+Shift+D 转自:http://blog.csdn.net/zxwd2015/article/ ...

  7. racktables 后期维护

    一.网站与数据库分离 vim secret.php #$pdo_dsn = 'mysql:host=localhost;dbname=racktables'; #$db_username = 'roo ...

  8. python之语音识别(speech模块)

    1.原理 语音操控分为 语音识别和语音朗读两部分. 这两部分本来是需要自然语言处理技能相关知识以及一系列极其复杂的算法才能搞定,可是这篇文章将会跳过此处,如果你只是对算法和自然语言学感兴趣的话,就只有 ...

  9. Cisco 4507R+E四引擎VSS故障解决

    如果可以要做双引擎VSS(每个机箱1个引擎), 3.6.7版本可以实现 如果需要做4引擎VSS(每个机箱2个引擎) 请使用3.8.x和之后的版本.

  10. Codeforces Beta Round #40 (Div. 2)

    Codeforces Beta Round #40 (Div. 2) http://codeforces.com/contest/41 A #include<bits/stdc++.h> ...