Linux 在类 Unix 系统中上次运行的 cron 作业的详细信息?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11131490/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Details of last ran cron job in Unix-like systems?
提问by kannanrbk
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.
注意:我没有超级用户权限。
采纳答案by Stecman
You can see the date, time, user and command of previously executed cron jobs using:
您可以使用以下命令查看以前执行的 cron 作业的日期、时间、用户和命令:
grep CRON /var/log/syslog
This will show allcron 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 jobso 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:
编辑:如果您没有 root 访问权限,则必须保留自己的作业日志。这可以简单地通过将以下内容添加到作业命令的末尾来完成:
&& 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
回答by Vijay Vasanth
/var/log/cron
contains cron job logs. But you need a root privilege to see.
/var/log/cron
包含 cron 作业日志。但是你需要一个root权限才能看到。
回答by yen leidong
CentOs,
sudo grep CRON /var/log/cron
CentO,
sudo grep CRON /var/log/cron