int do_check_log2()
{
FILE *fh = fopen( "./.outlog2", "r" );
if( !fh )
{
DebugMsg( "Error: fail to open .outlog2/n" );
return 0;
}
char buf[MAX_PATH] = {'/0'};
char key[MAX_PATH] = {'/0'};
char value[10] = {'/0'};
while( !feof(fh) )
{
memset(buf,0,sizeof(buf));
memset(key,0,sizeof(key));
memset(value,0,sizeof(value));
fgets( buf, sizeof(buf)-1, fh );
if( buf[0] == 0 || isspace(buf[0])|| strlen(buf)<4)
{
DebugMsg( "break read .outlog2/n" );
break;
}
if (buf[strlen(buf)-1]=='/n')//delete/r/n
{
buf[strlen(buf)-1]=0;
}
if (buf[strlen(buf)-1]=='/r')
{
buf[strlen(buf)-1]=0;
}
strncpy( value, buf, 1 );
strncpy( key, buf+2, sizeof(key) );
if( !strcmp(key, "status") )
{
if( strcmp(value, "0" ) == 0 )
{
DebugMsg( "Error: do_check_log2.pl error exit/n" );
break;
}
}else
{
if( strcmp( value, "1" ) == 0 ) //one file abnornal, and need to send alarm
{
SendUdpmsg("<msg>log2_file_alarm</msg><time>%d</time><content>%s</content>",time(NULL),key);
}
}
}
fclose( fh );
return 1;
}
c读文件且注意换行符
最新推荐文章于 2021-08-02 17:32:05 发布