[GRASSLIST:4585] Re: .tmp files
Leonard Coop
coopl at ucs.orst.edu
Wed Sep 25 14:30:10 EDT 2002
One way to do it with perl:
----------------------
#!/usr/bin/perl -w
# cleanup GRASS temp files, for example put in roots crontab:
#04 06 * * * cd /locationofthisscript; ./clean_tmp.pl
#
my $oldest = 2.0; # oldest age in days ex 0.25=6 hrs
my @dirs = ("/usr/local/grassdata/locname/mapset1/.tmp/servername/",
"/usr/local/grassdata/locname/mapset2/.tmp/servername/");
my $filename = "";
foreach my $dirname (@dirs) {
opendir(DIR, $dirname) or die "cant opendir $dirname: $!";
while (defined($filename = readdir(DIR))) {
my $fullname = $dirname . $filename;
if (-f $fullname) {
my $age = (-M $fullname);
unlink($fullname) || warn "cant rm $fullname $!" unless $age <
$oldest;
}
}
closedir(DIR);
}
------------------------
Its working for me,
Len Coop
On Tue, 24 Sep 2002, Glynn Clements wrote:
>
> Gordon Keith wrote:
>
> > > The ".tmp" directory should get cleaned whenever you exit a GRASS
> > > session.
> > >
> > > If your ".tmp" directories are accumulating files, that suggests that
> > > GRASS sessions are being terminated abnormally, e.g. by killing the
> > > xterm. Always terminate the session by typing "exit" in the shell.
> >
> > OK.
> >
> > It's probably my fault then.
> >
> > I've been using g.gisenv set= to swap better mapsets and locations a lot
> > rather than having to exit and restart grass several times a day. I
> > guess this is one of the gotchas of doing that.
>
> OK; yes, the other reason why temporary files may accumulate is if you
> have long-running sessions. Until recently this seldom happened, as
> you had to quit in order to change the location or mapset.
>
> Either terminate the session at the end of the day, or manually run
> $GISBASE/etc/clean_temp occasionally. Unfortunately, this can't be
> automated, as a few programs expect temporary files to survive for a
> while after the program which created them has terminated.
>
> Mostly this is due to either:
>
> a) a program creating a temporary file, then running some other
> program with that temporary file as input.
>
> b) d.text, which saves its input in a temporary file; this file needs
> to remain until the monitor is erased, as it will be used if the
> monitor needs to be redrawn (either via d.resize/d.redraw or, for
> XDRIVER, if the monitor is resized via the window manager).
>
> Apart from that, I suspect that a lot of programs need to take more
> care to remove temporary files once they are no longer needed.
>
> --
> Glynn Clements <glynn.clements at virgin.net>
>
>
More information about the grass-user
mailing list