如何测试每周的cron作业?

时间:2021-03-30 05:54:59

I have a #!/bin/bash file in cron.week directory.

我有# !在cron /bin/bash文件。周目录。

Is there a way to test if it works? Can't wait 1 week

是否有办法测试它是否有效?不能等待1周

I am on Debian 6 with root

我在Debian 6上有根。

11 个解决方案

#1


213  

Just do what cron does, run the following as root:

做cron做的事情,把下面的作为根:

run-parts -v /etc/cron.weekly

or

run-parts /etc/cron.weekly -v

if you receive the "Not a directory: -v" error.

如果您收到“Not a directory: -v”错误。

-v prints the script names before they are run.

-v在运行之前打印脚本名称。

#2


69  

A wee bit beyond the scope of your question... but here's what I do.

超出了你的问题范围……但我是这么做的。

The "how do I test a cron job?" question is closely connected to "how do I test scripts that run in non-interactive contexts launched by other programs?" In cron, the trigger is some time condition, but lots of other *nix facilities launch scripts or script fragments in non-interactive ways, and often the conditions in which those scripts run contain something unexpected and cause breakage until the bugs are sorted out.

“我如何测试cron作业?”问题与“我如何测试其他程序启动的非交互式上下文的脚本”密切相关。在cron中,触发器是一些时间条件,但是许多其他的*nix工具以非交互的方式启动脚本或脚本片段,并且通常这些脚本运行的条件包含一些意想不到的东西,并导致错误,直到bug被解决。

A general approach to this problem is helpful to have.

对这个问题的一般方法是有帮助的。

One of my favorite techniques is to use a script I wrote called 'crontest'. It launches the target command inside a GNU screen session from within cron, so that you can attach with a separate terminal to see what's going on, interact with the script, even use a debugger.

我最喜欢的技术之一是使用我写的“crontest”脚本。它从cron内部启动一个GNU screen会话中的目标命令,这样您就可以附加一个单独的终端来查看发生了什么,与脚本交互,甚至使用调试器。

To set this up, you would use "all stars" in your crontab entry, and specify crontest as the first command on the command line, e.g.:

要设置这个,您将在crontab条目中使用“all stars”,并将crontest指定为命令行上的第一个命令,例如:

* * * * * crontest /command/to/be/tested --param1 --param2

So now cron will run your command every minute, but crontest will ensure that only one instance runs at a time. If the command takes time to run, you can do a "screen -x" to attach and watch it run. If the command is a script, you can put a "read" command at the top to make it stop and wait for the screen attachment to complete (hit enter after attaching)

现在cron将每分钟运行一次命令,但是crontest将确保每次只运行一个实例。如果命令需要时间运行,您可以执行一个“屏幕-x”来连接并观察它运行。如果该命令是一个脚本,您可以在顶部放置一个“read”命令,使其停止并等待屏幕附件完成(在附加后点击进入)

If your command is a bash script, you can do this instead:

如果您的命令是bash脚本,您可以这样做:

* * * * * crontest --bashdb /command/to/be/tested --param1 --param2

Now, if you attach with "screen -x", you'll be facing an interactive bashdb session, and you can step through the code, examine variables, etc.

现在,如果您使用“screen -x”,您将面对一个交互式bashdb会话,您可以跨出代码、检查变量等。

#!/bin/bash

# crontest
# See https://github.com/Stabledog/crontest for canonical source.

# Test wrapper for cron tasks.  The suggested use is:
#
#  1. When adding your cron job, use all 5 stars to make it run every minute
#  2. Wrap the command in crontest
#        
#
#  Example:
#
#  $ crontab -e
#     * * * * * /usr/local/bin/crontest $HOME/bin/my-new-script --myparams
#
#  Now, cron will run your job every minute, but crontest will only allow one
#  instance to run at a time.  
#
#  crontest always wraps the command in "screen -d -m" if possible, so you can
#  use "screen -x" to attach and interact with the job.   
#
#  If --bashdb is used, the command line will be passed to bashdb.  Thus you
#  can attach with "screen -x" and debug the remaining command in context.
#
#  NOTES:
#   - crontest can be used in other contexts, it doesn't have to be a cron job.
#       Any place where commands are invoked without an interactive terminal and
#       may need to be debugged.
#
#   - crontest writes its own stuff to /tmp/crontest.log
#
#   - If GNU screen isn't available, neither is --bashdb
#

crontestLog=/tmp/crontest.log
lockfile=$(if [[ -d /var/lock ]]; then echo /var/lock/crontest.lock; else echo /tmp/crontest.lock; fi )
useBashdb=false
useScreen=$( if which screen &>/dev/null; then echo true; else echo false; fi )
innerArgs="$@"
screenBin=$(which screen 2>/dev/null)

function errExit {
    echo "[-err-] $@" | tee -a $crontestLog >&2
}

function log {
    echo "[-stat-] $@" >> $crontestLog
}

function parseArgs {
    while [[ ! -z $1 ]]; do
        case $1 in
            --bashdb)
                if ! $useScreen; then
                    errExit "--bashdb invalid in crontest because GNU screen not installed"
                fi
                if ! which bashdb &>/dev/null; then
                    errExit "--bashdb invalid in crontest: no bashdb on the PATH"
                fi

                useBashdb=true
                ;;
            --)
                shift
                innerArgs="$@"
                return 0
                ;;
            *)
                innerArgs="$@"
                return 0
                ;;
        esac
        shift
    done
}

if [[ -z  $sourceMe ]]; then
    # Lock the lockfile (no, we do not wish to follow the standard
    # advice of wrapping this in a subshell!)
    exec 9>$lockfile
    flock -n 9 || exit 1

    # Zap any old log data:
    [[ -f $crontestLog ]] && rm -f $crontestLog

    parseArgs "$@"

    log "crontest starting at $(date)"
    log "Raw command line: $@"
    log "Inner args: $@"
    log "screenBin: $screenBin"
    log "useBashdb: $( if $useBashdb; then echo YES; else echo no; fi )"
    log "useScreen: $( if $useScreen; then echo YES; else echo no; fi )"

    # Were building a command line.
    cmdline=""

    # If screen is available, put the task inside a pseudo-terminal
    # owned by screen.  That allows the developer to do a "screen -x" to
    # interact with the running command:
    if $useScreen; then
        cmdline="$screenBin -D -m "
    fi

    # If bashdb is installed and --bashdb is specified on the command line,
    # pass the command to bashdb.  This allows the developer to do a "screen -x" to
    # interactively debug a bash shell script:
    if $useBashdb; then
        cmdline="$cmdline $(which bashdb) "
    fi

    # Finally, append the target command and params:
    cmdline="$cmdline $innerArgs"

    log "cmdline: $cmdline"


    # And run the whole schlock:
    $cmdline 

    res=$?

    log "Command result: $res"


    echo "[-result-] $(if [[ $res -eq 0 ]]; then echo ok; else echo fail; fi)" >> $crontestLog

    # Release the lock:
    9<&-
fi

#3


36  

After messing about with some stuff in cron which wasn't instantly compatible I found that the following approach was nice for debugging:

在对cron中不立即兼容的一些东西进行了处理之后,我发现下面的方法对调试很好:

crontab -e

* * * * * /path/to/prog var1 var2 &>>/tmp/cron_debug_log.log

This will run the task once a minute and you can simply look in the /tmp/cron_debug_log.log file to figure out what is going on.

这将每分钟运行一次任务,您可以简单地查看/tmp/cron_debug_log。记录文件以查明正在发生的事情。

It is not exactly the "fire job" you might be looking for, but this helped me a lot when debugging a script that didn't work in cron at first.

这并不完全是您可能要寻找的“救火工作”,但是这在调试一个在cron中没有工作的脚本时帮助了我很多。

#4


23  

I'd use a lock file and then set the cron job to run every minute. (use crontab -e and * * * * * /path/to/job) That way you can just keep editing the files and each minute they'll be tested out. Additionally, you can stop the cronjob by just touching the lock file.

我将使用一个锁文件,然后将cron作业设置为每分钟运行一次。(使用crontab -e和* * * * * /path/to/job)这样你就可以继续编辑文件,每一分钟都将被测试。此外,您可以通过触摸锁文件来停止cronjob。

    #!/bin/sh
    if [ -e /tmp/cronlock ]
    then
        echo "cronjob locked"
        exit 1
    fi

    touch /tmp/cronlock
    <...do your regular cron here ....>
    rm -f /tmp/cronlock

#5


6  

What about putting it into cron.hourly, waiting until the next run of hourly cron jobs, then removing it? That would run it once within an hour, and in the cron environment. You can also run ./your_script, but that won't have the same environment as under cron.

把它放进cron里怎么样?每小时,等到下一个小时的cron作业,然后移除它?这将在一个小时内,在cron环境中运行一次。您也可以运行。/your_script,但是这与cron的环境不一样。

#6


4  

Aside from that you can also use:

除此之外,你还可以使用:

http://pypi.python.org/pypi/cronwrap

http://pypi.python.org/pypi/cronwrap

to wrap up your cron to send you an email upon success or failure.

把你的cron包装起来,在成功或失败的时候给你发邮件。

#7


3  

None of these answers fit my specific situation, which was that I wanted to run one specific cron job, just once, and run it immediately.

这些答案没有一个符合我的具体情况,那就是我想要运行一个特定的cron作业,只要一次,然后立即运行它。

I'm on a Ubuntu server, and I use cPanel to setup my cron jobs.

我在Ubuntu服务器上,我用cPanel来设置我的cron作业。

I simply wrote down my current settings, and then edited them to be one minute from now. When I fixed another bug, I just edited it again to one minute from now. And when I was all done, I just reset the settings back to how they were before.

我只是简单地写下我当前的设置,然后编辑它们,从现在开始一分钟。当我修复另一个错误时,我只是从现在开始重新编辑它。当我全部完成后,我将设置重新设置回到之前的状态。

Example: It's 4:34pm right now, so I put 35 16 * * *, for it to run at 16:35.

例子:现在是下午4点34分,所以我放了3516 * * *,让它在16点35分运行。

It worked like a charm, and the most I ever had to wait was a little less than one minute.

它就像一种魅力,而我所要等待的最多只有不到一分钟。

I thought this was a better option than some of the other answers because I didn't want to run all of my weekly crons, and I didn't want the job to run every minute. It takes me a few minutes to fix whatever the issues were before I'm ready to test it again. Hopefully this helps someone.

我认为这是一个比其他答案更好的选择,因为我不想运行我的每周crons,而且我也不想让这个工作每分钟都运行。在我准备再次测试之前,我需要花几分钟时间来解决问题。希望这可以帮助别人。

#8


2  

I normally test by running the job i created like this:

我通常通过运行我创建的这个工作来测试:

It is easier to use two terminals to do this.

使用两个终端来完成这个任务比较容易。

run job:

运行工作:

#./jobname.sh

go to:

至:

#/var/log and run 

run the following:

运行以下:

#tailf /var/log/cron

This allows me to see the cron logs update in real time. You can also review the log after you run it, I prefer watching in real time.

这让我可以实时看到cron日志的更新。你也可以在运行后查看日志,我更喜欢实时观看。

Here is an example of a simple cron job. Running a yum update...

下面是一个简单的cron作业的例子。运行yum更新……

#!/bin/bash
YUM=/usr/bin/yum
$YUM -y -R 120 -d 0 -e 0 update yum
$YUM -y -R 10 -e 0 -d 0 update

Here is the breakdown:

这是分解:

First command will update yum itself and next will apply system updates.

第一个命令将更新yum本身,接下来将应用系统更新。

-R 120 : Sets the maximum amount of time yum will wait before performing a command

- r120:设置yum在执行命令之前等待的最长时间。

-e 0 : Sets the error level to 0 (range 0 - 10). 0 means print only critical errors about which you must be told.

- e0:将错误级别设置为0(范围0 - 10)。0意味着只打印必须告知的关键错误。

-d 0 : Sets the debugging level to 0 - turns up or down the amount of things that are printed. (range: 0 - 10).

- d0:将调试级别设置为0—显示打印的内容的数量。(范围:0 - 10)。

-y : Assume yes; assume that the answer to any question which would be asked is yes

可能是:假设是的;假设任何问题的答案都是肯定的。

After I built the cron job I ran the below command to make my job executable.

在我构建了cron作业之后,我运行下面的命令,以使我的工作可执行。

#chmod +x /etc/cron.daily/jobname.sh 

Hope this helps, Dorlack

希望这有助于,Dorlack

#9


2  

The solution I am using is as follows:

我使用的解决方案如下:

  1. Edit crontab(use command :crontab -e) to run the job as frequently as needed (every 1 minute or 5 minutes)
  2. 编辑crontab(使用命令:crontab -e)在需要时尽可能频繁地运行该作业(每1分钟或5分钟)
  3. Modify the shell script which should be executed using cron to prints the output into some file (e.g: echo "Working fine" >>
    output.txt)
  4. 修改shell脚本,该脚本应该使用cron将输出输出到某个文件(e)。g: echo "Working fine" >> output.txt
  5. Check the output.txt file using the command : tail -f output.txt, which will print the latest additions into this file, and thus you can track the execution of the script
  6. 检查输出。使用命令的txt文件:tail -f输出。txt,它将打印最新的添加到这个文件中,因此您可以跟踪脚本的执行。

#10


1  

sudo run-parts --test /var/spool/cron/crontabs/

files in that crontabs/ directory needs to be executable by owner - octal 700

crontabs/目录中的文件需要由所有者- octal 700执行。

source: man cron and NNRooth's

来源:man cron和NNRooth's。

#11


0  

I'm using Webmin because its a productivity gem for someone who finds command line administration a bit daunting and impenetrable.

我正在使用Webmin,因为它是一种生产力的宝石,因为有人觉得命令行管理有点令人生畏和难以理解。

There is a "Save and Run Now" button in the "System > Scheduled Cron Jobs > Edit Cron Job" web interface.

有一个“保存和运行现在”按钮在“系统>计划的Cron工作>编辑Cron作业”的网页界面。

It displays the output of the command and is exactly what I needed.

它显示命令的输出,正是我所需要的。

#1


213  

Just do what cron does, run the following as root:

做cron做的事情,把下面的作为根:

run-parts -v /etc/cron.weekly

or

run-parts /etc/cron.weekly -v

if you receive the "Not a directory: -v" error.

如果您收到“Not a directory: -v”错误。

-v prints the script names before they are run.

-v在运行之前打印脚本名称。

#2


69  

A wee bit beyond the scope of your question... but here's what I do.

超出了你的问题范围……但我是这么做的。

The "how do I test a cron job?" question is closely connected to "how do I test scripts that run in non-interactive contexts launched by other programs?" In cron, the trigger is some time condition, but lots of other *nix facilities launch scripts or script fragments in non-interactive ways, and often the conditions in which those scripts run contain something unexpected and cause breakage until the bugs are sorted out.

“我如何测试cron作业?”问题与“我如何测试其他程序启动的非交互式上下文的脚本”密切相关。在cron中,触发器是一些时间条件,但是许多其他的*nix工具以非交互的方式启动脚本或脚本片段,并且通常这些脚本运行的条件包含一些意想不到的东西,并导致错误,直到bug被解决。

A general approach to this problem is helpful to have.

对这个问题的一般方法是有帮助的。

One of my favorite techniques is to use a script I wrote called 'crontest'. It launches the target command inside a GNU screen session from within cron, so that you can attach with a separate terminal to see what's going on, interact with the script, even use a debugger.

我最喜欢的技术之一是使用我写的“crontest”脚本。它从cron内部启动一个GNU screen会话中的目标命令,这样您就可以附加一个单独的终端来查看发生了什么,与脚本交互,甚至使用调试器。

To set this up, you would use "all stars" in your crontab entry, and specify crontest as the first command on the command line, e.g.:

要设置这个,您将在crontab条目中使用“all stars”,并将crontest指定为命令行上的第一个命令,例如:

* * * * * crontest /command/to/be/tested --param1 --param2

So now cron will run your command every minute, but crontest will ensure that only one instance runs at a time. If the command takes time to run, you can do a "screen -x" to attach and watch it run. If the command is a script, you can put a "read" command at the top to make it stop and wait for the screen attachment to complete (hit enter after attaching)

现在cron将每分钟运行一次命令,但是crontest将确保每次只运行一个实例。如果命令需要时间运行,您可以执行一个“屏幕-x”来连接并观察它运行。如果该命令是一个脚本,您可以在顶部放置一个“read”命令,使其停止并等待屏幕附件完成(在附加后点击进入)

If your command is a bash script, you can do this instead:

如果您的命令是bash脚本,您可以这样做:

* * * * * crontest --bashdb /command/to/be/tested --param1 --param2

Now, if you attach with "screen -x", you'll be facing an interactive bashdb session, and you can step through the code, examine variables, etc.

现在,如果您使用“screen -x”,您将面对一个交互式bashdb会话,您可以跨出代码、检查变量等。

#!/bin/bash

# crontest
# See https://github.com/Stabledog/crontest for canonical source.

# Test wrapper for cron tasks.  The suggested use is:
#
#  1. When adding your cron job, use all 5 stars to make it run every minute
#  2. Wrap the command in crontest
#        
#
#  Example:
#
#  $ crontab -e
#     * * * * * /usr/local/bin/crontest $HOME/bin/my-new-script --myparams
#
#  Now, cron will run your job every minute, but crontest will only allow one
#  instance to run at a time.  
#
#  crontest always wraps the command in "screen -d -m" if possible, so you can
#  use "screen -x" to attach and interact with the job.   
#
#  If --bashdb is used, the command line will be passed to bashdb.  Thus you
#  can attach with "screen -x" and debug the remaining command in context.
#
#  NOTES:
#   - crontest can be used in other contexts, it doesn't have to be a cron job.
#       Any place where commands are invoked without an interactive terminal and
#       may need to be debugged.
#
#   - crontest writes its own stuff to /tmp/crontest.log
#
#   - If GNU screen isn't available, neither is --bashdb
#

crontestLog=/tmp/crontest.log
lockfile=$(if [[ -d /var/lock ]]; then echo /var/lock/crontest.lock; else echo /tmp/crontest.lock; fi )
useBashdb=false
useScreen=$( if which screen &>/dev/null; then echo true; else echo false; fi )
innerArgs="$@"
screenBin=$(which screen 2>/dev/null)

function errExit {
    echo "[-err-] $@" | tee -a $crontestLog >&2
}

function log {
    echo "[-stat-] $@" >> $crontestLog
}

function parseArgs {
    while [[ ! -z $1 ]]; do
        case $1 in
            --bashdb)
                if ! $useScreen; then
                    errExit "--bashdb invalid in crontest because GNU screen not installed"
                fi
                if ! which bashdb &>/dev/null; then
                    errExit "--bashdb invalid in crontest: no bashdb on the PATH"
                fi

                useBashdb=true
                ;;
            --)
                shift
                innerArgs="$@"
                return 0
                ;;
            *)
                innerArgs="$@"
                return 0
                ;;
        esac
        shift
    done
}

if [[ -z  $sourceMe ]]; then
    # Lock the lockfile (no, we do not wish to follow the standard
    # advice of wrapping this in a subshell!)
    exec 9>$lockfile
    flock -n 9 || exit 1

    # Zap any old log data:
    [[ -f $crontestLog ]] && rm -f $crontestLog

    parseArgs "$@"

    log "crontest starting at $(date)"
    log "Raw command line: $@"
    log "Inner args: $@"
    log "screenBin: $screenBin"
    log "useBashdb: $( if $useBashdb; then echo YES; else echo no; fi )"
    log "useScreen: $( if $useScreen; then echo YES; else echo no; fi )"

    # Were building a command line.
    cmdline=""

    # If screen is available, put the task inside a pseudo-terminal
    # owned by screen.  That allows the developer to do a "screen -x" to
    # interact with the running command:
    if $useScreen; then
        cmdline="$screenBin -D -m "
    fi

    # If bashdb is installed and --bashdb is specified on the command line,
    # pass the command to bashdb.  This allows the developer to do a "screen -x" to
    # interactively debug a bash shell script:
    if $useBashdb; then
        cmdline="$cmdline $(which bashdb) "
    fi

    # Finally, append the target command and params:
    cmdline="$cmdline $innerArgs"

    log "cmdline: $cmdline"


    # And run the whole schlock:
    $cmdline 

    res=$?

    log "Command result: $res"


    echo "[-result-] $(if [[ $res -eq 0 ]]; then echo ok; else echo fail; fi)" >> $crontestLog

    # Release the lock:
    9<&-
fi

#3


36  

After messing about with some stuff in cron which wasn't instantly compatible I found that the following approach was nice for debugging:

在对cron中不立即兼容的一些东西进行了处理之后,我发现下面的方法对调试很好:

crontab -e

* * * * * /path/to/prog var1 var2 &>>/tmp/cron_debug_log.log

This will run the task once a minute and you can simply look in the /tmp/cron_debug_log.log file to figure out what is going on.

这将每分钟运行一次任务,您可以简单地查看/tmp/cron_debug_log。记录文件以查明正在发生的事情。

It is not exactly the "fire job" you might be looking for, but this helped me a lot when debugging a script that didn't work in cron at first.

这并不完全是您可能要寻找的“救火工作”,但是这在调试一个在cron中没有工作的脚本时帮助了我很多。

#4


23  

I'd use a lock file and then set the cron job to run every minute. (use crontab -e and * * * * * /path/to/job) That way you can just keep editing the files and each minute they'll be tested out. Additionally, you can stop the cronjob by just touching the lock file.

我将使用一个锁文件,然后将cron作业设置为每分钟运行一次。(使用crontab -e和* * * * * /path/to/job)这样你就可以继续编辑文件,每一分钟都将被测试。此外,您可以通过触摸锁文件来停止cronjob。

    #!/bin/sh
    if [ -e /tmp/cronlock ]
    then
        echo "cronjob locked"
        exit 1
    fi

    touch /tmp/cronlock
    <...do your regular cron here ....>
    rm -f /tmp/cronlock

#5


6  

What about putting it into cron.hourly, waiting until the next run of hourly cron jobs, then removing it? That would run it once within an hour, and in the cron environment. You can also run ./your_script, but that won't have the same environment as under cron.

把它放进cron里怎么样?每小时,等到下一个小时的cron作业,然后移除它?这将在一个小时内,在cron环境中运行一次。您也可以运行。/your_script,但是这与cron的环境不一样。

#6


4  

Aside from that you can also use:

除此之外,你还可以使用:

http://pypi.python.org/pypi/cronwrap

http://pypi.python.org/pypi/cronwrap

to wrap up your cron to send you an email upon success or failure.

把你的cron包装起来,在成功或失败的时候给你发邮件。

#7


3  

None of these answers fit my specific situation, which was that I wanted to run one specific cron job, just once, and run it immediately.

这些答案没有一个符合我的具体情况,那就是我想要运行一个特定的cron作业,只要一次,然后立即运行它。

I'm on a Ubuntu server, and I use cPanel to setup my cron jobs.

我在Ubuntu服务器上,我用cPanel来设置我的cron作业。

I simply wrote down my current settings, and then edited them to be one minute from now. When I fixed another bug, I just edited it again to one minute from now. And when I was all done, I just reset the settings back to how they were before.

我只是简单地写下我当前的设置,然后编辑它们,从现在开始一分钟。当我修复另一个错误时,我只是从现在开始重新编辑它。当我全部完成后,我将设置重新设置回到之前的状态。

Example: It's 4:34pm right now, so I put 35 16 * * *, for it to run at 16:35.

例子:现在是下午4点34分,所以我放了3516 * * *,让它在16点35分运行。

It worked like a charm, and the most I ever had to wait was a little less than one minute.

它就像一种魅力,而我所要等待的最多只有不到一分钟。

I thought this was a better option than some of the other answers because I didn't want to run all of my weekly crons, and I didn't want the job to run every minute. It takes me a few minutes to fix whatever the issues were before I'm ready to test it again. Hopefully this helps someone.

我认为这是一个比其他答案更好的选择,因为我不想运行我的每周crons,而且我也不想让这个工作每分钟都运行。在我准备再次测试之前,我需要花几分钟时间来解决问题。希望这可以帮助别人。

#8


2  

I normally test by running the job i created like this:

我通常通过运行我创建的这个工作来测试:

It is easier to use two terminals to do this.

使用两个终端来完成这个任务比较容易。

run job:

运行工作:

#./jobname.sh

go to:

至:

#/var/log and run 

run the following:

运行以下:

#tailf /var/log/cron

This allows me to see the cron logs update in real time. You can also review the log after you run it, I prefer watching in real time.

这让我可以实时看到cron日志的更新。你也可以在运行后查看日志,我更喜欢实时观看。

Here is an example of a simple cron job. Running a yum update...

下面是一个简单的cron作业的例子。运行yum更新……

#!/bin/bash
YUM=/usr/bin/yum
$YUM -y -R 120 -d 0 -e 0 update yum
$YUM -y -R 10 -e 0 -d 0 update

Here is the breakdown:

这是分解:

First command will update yum itself and next will apply system updates.

第一个命令将更新yum本身,接下来将应用系统更新。

-R 120 : Sets the maximum amount of time yum will wait before performing a command

- r120:设置yum在执行命令之前等待的最长时间。

-e 0 : Sets the error level to 0 (range 0 - 10). 0 means print only critical errors about which you must be told.

- e0:将错误级别设置为0(范围0 - 10)。0意味着只打印必须告知的关键错误。

-d 0 : Sets the debugging level to 0 - turns up or down the amount of things that are printed. (range: 0 - 10).

- d0:将调试级别设置为0—显示打印的内容的数量。(范围:0 - 10)。

-y : Assume yes; assume that the answer to any question which would be asked is yes

可能是:假设是的;假设任何问题的答案都是肯定的。

After I built the cron job I ran the below command to make my job executable.

在我构建了cron作业之后,我运行下面的命令,以使我的工作可执行。

#chmod +x /etc/cron.daily/jobname.sh 

Hope this helps, Dorlack

希望这有助于,Dorlack

#9


2  

The solution I am using is as follows:

我使用的解决方案如下:

  1. Edit crontab(use command :crontab -e) to run the job as frequently as needed (every 1 minute or 5 minutes)
  2. 编辑crontab(使用命令:crontab -e)在需要时尽可能频繁地运行该作业(每1分钟或5分钟)
  3. Modify the shell script which should be executed using cron to prints the output into some file (e.g: echo "Working fine" >>
    output.txt)
  4. 修改shell脚本,该脚本应该使用cron将输出输出到某个文件(e)。g: echo "Working fine" >> output.txt
  5. Check the output.txt file using the command : tail -f output.txt, which will print the latest additions into this file, and thus you can track the execution of the script
  6. 检查输出。使用命令的txt文件:tail -f输出。txt,它将打印最新的添加到这个文件中,因此您可以跟踪脚本的执行。

#10


1  

sudo run-parts --test /var/spool/cron/crontabs/

files in that crontabs/ directory needs to be executable by owner - octal 700

crontabs/目录中的文件需要由所有者- octal 700执行。

source: man cron and NNRooth's

来源:man cron和NNRooth's。

#11


0  

I'm using Webmin because its a productivity gem for someone who finds command line administration a bit daunting and impenetrable.

我正在使用Webmin,因为它是一种生产力的宝石,因为有人觉得命令行管理有点令人生畏和难以理解。

There is a "Save and Run Now" button in the "System > Scheduled Cron Jobs > Edit Cron Job" web interface.

有一个“保存和运行现在”按钮在“系统>计划的Cron工作>编辑Cron作业”的网页界面。

It displays the output of the command and is exactly what I needed.

它显示命令的输出,正是我所需要的。