关于上次在类unix系统中运行cron任务的细节?

时间:2022-03-20 01:42:48

I want to get the details of the last run cron job. If the job is interrupted due to some internal problems, I want to re-run the cron job.

我想知道上次cron工作的细节。如果工作因为一些内部问题而中断,我想重新运行cron作业。

Note: I don't have superuser privilege.

注意:我没有超级用户特权。

2 个解决方案

#1


58  

You can see the date, time, user and command of previously executed cron jobs using:

您可以使用以下命令查看以前执行的cron作业的日期、时间、用户和命令:

grep CRON /var/log/syslog

This will show all cron jobs. If you only wanted to see jobs run by a certain user, you would use something like this:

这将显示所有的cron工作。如果您只想看到某个用户运行的作业,您可以使用以下内容:

grep CRON.*\(root\) /var/log/syslog

Note that cron logs at the start of a job so you may want to have lengthy jobs keep their own completion logs; if the system went down halfway through a job, it would still be in the log!

请注意,cron日志记录在作业开始时,因此您可能希望有冗长的作业保存自己的完成日志;如果系统在一份工作中半途而废,它仍然会在日志中!

Edit: If you don't have root access, you will have to keep your own job logs. This can be done simply by tacking the following onto the end of your job command:

编辑:如果您没有根访问,您将不得不保留您自己的工作日志。这可以简单地通过在你的工作命令的末尾加上以下内容来完成:

&& date > /home/user/last_completed

The file /home/user/last_completed would always contain the last date and time the job completed. You would use >> instead of > if you wanted to append completion dates to the file.

文件/home/user/last_completed总是包含作业完成的最后日期和时间。如果您希望在文件中附加完成日期,您将使用>>而不是>。

You could also achieve the same by putting your command in a small bash or sh script and have cron execute that file.

您也可以通过将命令放在一个小bash或sh脚本中并让cron执行该文件来实现这一点。

#!/bin/bash
[command]
date > /home/user/last_completed

The crontab for this would be:

为此,crontab将是:

* * * * * bash /path/to/script.bash

#2


10  

/var/log/cron contains cron job logs. But you need a root privilege to see.

/var/log/cron包含cron作业日志。但您需要root权限才能查看。

#1


58  

You can see the date, time, user and command of previously executed cron jobs using:

您可以使用以下命令查看以前执行的cron作业的日期、时间、用户和命令:

grep CRON /var/log/syslog

This will show all cron jobs. If you only wanted to see jobs run by a certain user, you would use something like this:

这将显示所有的cron工作。如果您只想看到某个用户运行的作业,您可以使用以下内容:

grep CRON.*\(root\) /var/log/syslog

Note that cron logs at the start of a job so you may want to have lengthy jobs keep their own completion logs; if the system went down halfway through a job, it would still be in the log!

请注意,cron日志记录在作业开始时,因此您可能希望有冗长的作业保存自己的完成日志;如果系统在一份工作中半途而废,它仍然会在日志中!

Edit: If you don't have root access, you will have to keep your own job logs. This can be done simply by tacking the following onto the end of your job command:

编辑:如果您没有根访问,您将不得不保留您自己的工作日志。这可以简单地通过在你的工作命令的末尾加上以下内容来完成:

&& date > /home/user/last_completed

The file /home/user/last_completed would always contain the last date and time the job completed. You would use >> instead of > if you wanted to append completion dates to the file.

文件/home/user/last_completed总是包含作业完成的最后日期和时间。如果您希望在文件中附加完成日期,您将使用>>而不是>。

You could also achieve the same by putting your command in a small bash or sh script and have cron execute that file.

您也可以通过将命令放在一个小bash或sh脚本中并让cron执行该文件来实现这一点。

#!/bin/bash
[command]
date > /home/user/last_completed

The crontab for this would be:

为此,crontab将是:

* * * * * bash /path/to/script.bash

#2


10  

/var/log/cron contains cron job logs. But you need a root privilege to see.

/var/log/cron包含cron作业日志。但您需要root权限才能查看。