shlle,每周5凌晨3点备份/var/log下的所有日志文件

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/zhaoxixc/article/details/85343185
#!/bin/bash
tar -zcvf log-`date +%Y%m%d`.tar.gz /var/log
[root@debug ~]# pwd
/root
[root@debug ~]# ll shell1.sh 
-rwxr-xr-x 1 root root 57 Dec 29 18:16 shell1.sh
[root@debug ~]# chmod +x shell1.sh 

[root@debug ~]# crontab -e
00 19 * * * /usr/bin/sh /root/shell1.sh
-rw-r--r--  1 root root 11421349 Dec 29 19:00 log-20181229.tar.gz
展开阅读全文

关于写log日志文件

04-01

我初学VC,如下一段程序是本人以前在c中用来写log信息以方便调试之用。现在需要在VC中用MFC的方式来实现写log的功能。真诚请教各位高手予以指点,本人感激不尽。rnrn#include "common.h"rn#include "prototypes.h"rnrnstatic FILE *outfile=NULL; /* Logging to file disabled by default */rnrnvoid log_open(void) rn int fd;rnrn fd=open(LOG_FILE, O_CREAT|O_WRONLY|O_APPEND, 0640);rn if(fd>=0) /* file opened or created */rn fcntl(fd, F_SETFD, FD_CLOEXEC);rn outfile=fdopen(fd, "a");rn if(outfile)rn return; /* no need to setup syslog */rn rn rnrnrnvoid log_close(void) rn if(outfile) rn fclose(outfile);rn return;rn rn rnrnvoid log(int level, const char *format, ...) rn va_list arglist;rn char text[STRLEN], timestamped[STRLEN];rn FILE *out;rn time_t gmt;rn struct tm *timeptr;rnrn va_start(arglist, format);rn#ifdef HAVE_VSNPRINTFrn vsnprintf(text, STRLEN, format, arglist);rn#elsern vsprintf(text, format, arglist);rn#endifrn va_end(arglist);rnrn out=outfile?outfile:stderr;rn time(&gmt);rn rn timeptr=localtime(&gmt);rnrn#ifdef HAVE_SNPRINTFrn snprintf(timestamped, STRLEN,rn#elsern sprintf(timestamped,rn#endifrn "%04d.%02d.%02d %02d:%02d:%02d LOG%d[%lu:%lu]: %s",rn timeptr->tm_year+1900, timeptr->tm_mon+1, timeptr->tm_mday,rn timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec,rn level, (unsigned long)getpid(), (unsigned long)pthread_self(), text);rn rn fprintf(out, "%s\n", timestamped);rn fflush(out);rn rnrnvoid log_raw(const char *format, ...) rn va_list arglist;rn char text[STRLEN];rn FILE *out;rnrn va_start(arglist, format);rn#ifdef HAVE_VSNPRINTFrn vsnprintf(text, STRLEN, format, arglist);rn#elsern vsprintf(text, format, arglist);rn#endifrn va_end(arglist);rnrn out=outfile?outfile:stderr;rn fprintf(out, "%s\n", text);rn fflush(out);rnrnrnvoid log_data(const char *buf)rn FILE* out;rn out=outfile?outfile:stderr;rn fprintf(out,"%s\n",buf);rn fflush(out);rnrnrnvoid log_error(int level, int error, char *txt) /* generic error logger */rn log(level, "%s: %s (%d)", txt, strerror(error), error);rnrnrn======================如何用mfc实现类似功能?多谢了。======================= 论坛

没有更多推荐了,返回首页