root / maintain.c @ 0:3c15de202295
History | View | Annotate | Download (1.53 KB)
1 |
#include <stdio.h> |
---|---|
2 |
|
3 |
int maintain_userlogs (char *user_logdir) |
4 |
{ |
5 |
char command[256]; |
6 |
int size=0,count=0; |
7 |
FILE *fs; |
8 |
char fname[30]; |
9 |
|
10 |
while (1) |
11 |
{ |
12 |
strcpy(command , "du -ch ");
|
13 |
strcat(command , user_logdir); |
14 |
strcat(command , " | awk 'END {print $1}' > size.txt");
|
15 |
system(command); |
16 |
printf ("%s\n",command);
|
17 |
|
18 |
fs=fopen("size.txt" , "r"); |
19 |
fscanf(fs,"%d",&size);
|
20 |
fclose(fs); |
21 |
system ("rm -f size.txt");
|
22 |
printf ("%d\n",size);
|
23 |
|
24 |
if (size >= 300) |
25 |
{ |
26 |
strcpy(command , "ls -1t ");
|
27 |
strcat(command , user_logdir); |
28 |
strcat(command , " | awk 'END {print $1}' > fname.txt");
|
29 |
system(command); |
30 |
printf ("%s\n",command);
|
31 |
|
32 |
fs=fopen("fname.txt" , "r"); |
33 |
fscanf(fs,"%s",fname);
|
34 |
fclose(fs); |
35 |
system ("rm -f fname.txt");
|
36 |
|
37 |
strcpy(command , "ls -1t ");
|
38 |
strcat(command , user_logdir); |
39 |
strcat(command , " | awk 'END{print NR,$1}' > count.txt");
|
40 |
system(command); |
41 |
printf ("%s\n",command);
|
42 |
|
43 |
fs=fopen("count.txt" , "r"); |
44 |
fscanf(fs,"%d,%s",&count,fname);
|
45 |
fclose(fs); |
46 |
system ("rm -f count.txt");
|
47 |
printf ("%d\n",count);
|
48 |
|
49 |
if (count <= 2) |
50 |
break;
|
51 |
|
52 |
strcpy(command , "rm -f ");
|
53 |
strcat(command , user_logdir); |
54 |
strcat(command , fname); |
55 |
system(command); |
56 |
printf ("%s\n",command);
|
57 |
} |
58 |
|
59 |
else
|
60 |
break;
|
61 |
} |
62 |
} |