static char sccsid
[] = "@(#)uuclean.c 5.6 (Berkeley) %G%";
* this program will search through the spool
* directory (Spool) and delete all files with a requested
* prefix which are older than (nomtime) seconds.
* If the -m option is set, the program will try to
* send mail to the usid of the file.
* -m - send mail for deleted file
* -d - directory to clean
* -n - time to age files before delete (in hours)
* -x - turn on debug outputs
* 1 - can not read directory
#define NOMTIME 72 /* hours to age files before deletion */
strcpy(Progname
, "uuclean");
nomtime
= NOMTIME
* (time_t)3600;
while (argc
>1 && argv
[1][0] == '-') {
nomtime
= atoi(&argv
[1][2]) * (time_t)3600;
Debug
= atoi(&argv
[1][2]);
printf("unknown flag %s\n", argv
[1]); break;
DEBUG(4, "DEBUG# %s\n", "START");
if (chdir(Spool
) < 0) { /* NO subdirs in uuclean! rti!trt */
printf("%s directory inaccessible\n", Spool
);
if ((dirp
= opendir(Spool
)) == NULL
) {
printf("%s directory unreadable\n", Spool
);
while (gnamef(dirp
, file
)) {
if (checkprefix
&& !chkpre(file
))
if (stat(file
, &stbuf
) == -1) {
DEBUG(4, "stat on %s failed\n", file
);
if ((stbuf
.st_mode
& S_IFMT
) == S_IFDIR
)
if ((ptime
- stbuf
.st_mtime
) < nomtime
)
DEBUG(4, "unlink file %s\n", file
);
sdmail(file
, stbuf
.st_uid
);
char Pre
[MAXPRE
][NAMESIZE
];
* chkpre(file) check for prefix
for (i
= 0; i
< Npre
; i
++) {
if (prefix(Pre
[i
], file
))
* notfyuser(file) - notfiy requestor of deleted requres
char frqst
[100], lrqst
[100];
if ((fp
= fopen(file
, "r")) == NULL
)
if (fgets(frqst
, 100, fp
) == NULL
) {
while (fgets(lrqst
, 100, fp
))
"File %s delete. \nCould not contact remote. \n%d requests deleted.\n", file
, numrq
);
strcat(msg
, "REQUEST: ");
strcat(msg
, "FIRST REQUEST: ");
strcat(msg
, "\nLAST REQUEST: ");
getargs(frqst
, args
, 10);
mailst(args
[3], msg
, CNULL
);
* sdmail - this routine will determine the owner
* of the file (file), create a message string and
* call "mailst" to send the cleanup message.
* This is only implemented for local system
static struct passwd
*pwd
;
struct passwd
*getpwuid();
sprintf(mstr
, "uuclean deleted file %s\n", file
);
if (pwd
!= NULL
&& pwd
->pw_uid
== uid
) {
mailst(pwd
->pw_name
, mstr
, CNULL
);
if ((pwd
= getpwuid(uid
)) != NULL
)
mailst(pwd
->pw_name
, mstr
, CNULL
);