当前位置:网站首页>Cronab log: how to record the output of my cron script
Cronab log: how to record the output of my cron script
2022-07-05 18:23:00 【Hua Weiyun】
I created a backup.sh shell Script and add it to my crontab To execute it every day . How to verify backup cron Whether the script job runs successfully ? Besides , my backup.sh shell There are several in the script echo sentence . When the script acts as cron When the job is performed , How to save the output of the script to the log file ?
Suppose you have backup.sh Add to your crontab in , As shown below , In order to execute it every morning .
$ crontab -e59 23 * * * /home/john/bin/backup.shTo verify whether this job was successfully executed , Please check /var/log/cron file , This file contains all the information about the execution in the system cron Job information . You can see from the following output ,john Of cron The job has been successfully executed .
$ tail /var/log/cronOct 8 22:00:00 dev-db crond[18340]: (root) CMD (/bin/sh /home/root/bin/system_check &)Oct 8 23:00:00 dev-db crond[20348]: (oracle) CMD (/bin/sh /home/oracle/bin/cleanup.sh &)Oct 8 23:59:00 dev-db crond[20399]: (john) CMD (/bin/sh /home/john/bin/backup.sh &)Cron The log contains the following information :
- Time stamp - perform cron The date and time of the assignment
- Host name – The hostname of the server ( for example dev-db)
- cron Daemon name and PID. for example ,crond[20399]
- user name – Execute this cron User name of the job . for example , John .
- CMD – Everything after that is the real order executed at that time .
If backup.sh Any of them echo sentence , You may want to record them in a file . Usually , If backup.sh cron The script throws any output ( Including mistakes ), You may want to record these outputs to a log file . So , Please amend crontab Entry and add output and error redirection , As shown below .
$ crontab -e59 23 * * * /home/john/bin/backup.sh > /home/john/logs/backup.log 2>&1on top :
- > /home/john/logs/backup.log It means that you will backup.sh The standard output of the script is redirected to backup.log file .
- 2>&1 Indicates a standard error (2>) Redirected to standard output (&1) Same file descriptor pointed to .
- therefore , Both standard output and errors will be redirected to /home/john/logs/backup.log
边栏推荐
- 【PaddleClas】常用命令
- Logical words in Articles
- Is it safe to open an account, register and dig money? Is there any risk? Is it reliable?
- Privacy computing helps secure data circulation and sharing
- 访问数据库使用redis作为mysql的缓存(redis和mysql结合)
- 从XML架构生成类
- 吴恩达团队2022机器学习课程,来啦
- 星环科技数据安全管理平台 Defensor重磅发布
- Penetrate the whole intranet through socks agent
- nacos -分布式事务-Seata** linux安装jdk ,mysql5.7启动nacos配置ideal 调用接口配合 (保姆级细节教程)
猜你喜欢

Simulate the hundred prisoner problem

Tupu software digital twin | visual management system based on BIM Technology

Huaxia Fund: sharing of practical achievements of digital transformation in the fund industry

ViewPager + RecyclerView的内存泄漏
![Whether to take a duplicate subset with duplicate elements [how to take a subset? How to remove duplicates?]](/img/b2/d019c3f0b85a6c0d334a092fa6c23c.png)
Whether to take a duplicate subset with duplicate elements [how to take a subset? How to remove duplicates?]

Memory management chapter of Kobayashi coding

《2022中国信创生态市场研究及选型评估报告》发布 华云数据入选信创IT基础设施主流厂商!

FCN: Fully Convolutional Networks for Semantic Segmentation

Sophon KG升级3.1:打破数据间壁垒,解放企业生产力

修复漏洞 - mysql 、es
随机推荐
音视频包的pts,dts,duration的由来.
The 10th global Cloud Computing Conference | Huayun data won the "special contribution award for the 10th anniversary of 2013-2022"
Copy the linked list with random pointer in the "Li Kou brush question plan"
华夏基金:基金行业数字化转型实践成果分享
buuctf-pwn write-ups (9)
nacos -分布式事务-Seata** linux安装jdk ,mysql5.7启动nacos配置ideal 调用接口配合 (保姆级细节教程)
Can communication of nano
Introduction to the development function of Hanlin Youshang system of Hansheng Youpin app
How to solve the error "press any to exit" when deploying multiple easycvr on one server?
星环科技重磅推出数据要素流通平台Transwarp Navier,助力企业实现隐私保护下的数据安全流通与协作
Star ring technology data security management platform defender heavy release
[utiliser Electron pour développer le Bureau sur youkirin devrait]
The easycvr platform reports an error "ID cannot be empty" through the interface editing channel. What is the reason?
Record eval() and no in pytoch_ grad()
Multithreading (I) processes and threads
node_exporter内存使用率不显示
小林coding的内存管理章节
使用JMeter录制脚本并调试
图扑软件数字孪生 | 基于 BIM 技术的可视化管理系统
记一次使用Windbg分析内存“泄漏”的案例