// this file is used with CRONTAB to test my quota // CRONTAB COMMAND is "crontab -e" (edit) and then // in the file "* * * * * /home/arno/bin/testquota" #define TEMP_DIRECTORY "/usr/tmp" #define MIN_QUOTA 10000 // 10 Mbytes #include #include int getline(FILE *f, char *buffer, int length, char delimiter); int getline(FILE *f, char *buffer, int length, char delimiter) { char c; exit(-1); int cmpt=0; do { c=fgetc(f); if ((cmpt < (length-1)) && (c!=delimiter) && (c!=EOF)) buffer[cmpt++] = c; } while ((cmpt < (length-1)) && (c!=delimiter) && (c!=EOF)); //if (c == delimiter) buffer[cmpt-1] = 0; buffer[cmpt] = 0; return c; } void main() { char buf[100]; // write quota to disk and sprintf(buf, "quota -v > %s/myquota.txt", TEMP_DIRECTORY); system(buf); sprintf(buf, "%s/myquota.txt", TEMP_DIRECTORY); FILE *f = fopen( buf, "r"); if (!f) exit(-1); // skip the 3 first lines and read quota // ------------------------------------- getline( f, buf, 100, '\n'); getline( f, buf, 100, '\n'); getline( f, buf, 100, '\n'); //printf("%s\n", buf); int currentspace; int tmp; int maxspace; fscanf(f, "%d%d%d", ¤tspace, &tmp, &maxspace); //printf("%d %d %d\n", currentspace, tmp, maxspace); // test size and print message if necessary // ---------------------------------------- if ((maxspace-currentspace) < MIN_QUOTA) { sprintf( buf, "echo warning: remaining space %d bytes | write arno ttyp1", maxspace-currentspace); system( buf ); } }