当前位置:网站首页>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.sh
To 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>&1
on 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
边栏推荐
猜你喜欢
U-Net: Convolutional Networks for Biomedical Images Segmentation
《力扣刷题计划》复制带随机指针的链表
瀚升优品app翰林优商系统开发功能介绍
rust统计文件中单词出现的次数
node_ Exporter memory usage is not displayed
记录Pytorch中的eval()和no_grad()
Maximum artificial island [how to make all nodes of a connected component record the total number of nodes? + number the connected component]
To solve the stubborn problem of Lake + warehouse hybrid architecture, xinghuan Technology launched an independent and controllable cloud native Lake warehouse integrated platform
Tupu software digital twin | visual management system based on BIM Technology
使用Jmeter虚拟化table失败
随机推荐
Introduction to VC programming on "suggestions collection"
分享:中兴 远航 30 pro root 解锁BL magisk ZTE 7532N 8040N 9041N 刷机 刷面具原厂刷机包 root方法下载
jdbc读大量数据导致内存溢出
What is the reason why the video cannot be played normally after the easycvr access device turns on the audio?
Sibling components carry out value transfer (there is a sequence displayed)
小林coding的内存管理章节
使用JMeter录制脚本并调试
Wu Enda team 2022 machine learning course, coming
The origin of PTS, DTS and duration of audio and video packages
彻底理解为什么网络 I/O 会被阻塞?
写作写作写作写作
Can communication of nano
Penetrate the whole intranet through socks agent
Einstein sum einsum
Multithreading (I) processes and threads
访问数据库使用redis作为mysql的缓存(redis和mysql结合)
Introduction to Resampling
多线程(一) 进程与线程
Copy the linked list with random pointer in the "Li Kou brush question plan"
[QNX hypervisor 2.2 user manual]6.3.2 configuring VM