Deleting expired sessions

Hi,

My tmp/sessions directory is getting flooded with files that AFAIK will
never get removed. I could write a cron job do do this but I was
wondering if that is really the most elegant and reusable way.

I’d like to create something that could be extracted into a plugin.
Would it be possible (and wise) to use an after_filter and backgrounddrb
to remove expired sessions? Any other suggestions?

Cheers,

Jeroen

Jeroen H. wrote:

Hi,

My tmp/sessions directory is getting flooded with files that AFAIK will
never get removed. I could write a cron job do do this but I was
wondering if that is really the most elegant and reusable way.

I’d like to create something that could be extracted into a plugin.
Would it be possible (and wise) to use an after_filter and backgrounddrb
to remove expired sessions? Any other suggestions?

For what it’s worth we just use a cron job that does find /tmp/sessions
-name ‘ruby_sess*’ -ctime +1 -exec rm -f {}
Not particularly beautiful but I’m not sure what there is to be gained
by doing things another way

Fred

Frederick C. wrote:

Jeroen H. wrote:

Hi,

My tmp/sessions directory is getting flooded with files that AFAIK will
never get removed. I could write a cron job do do this but I was
wondering if that is really the most elegant and reusable way.

I’d like to create something that could be extracted into a plugin.
Would it be possible (and wise) to use an after_filter and backgrounddrb
to remove expired sessions? Any other suggestions?

For what it’s worth we just use a cron job that does find /tmp/sessions
-name ‘ruby_sess*’ -ctime +1 -exec rm -f {}
Not particularly beautiful but I’m not sure what there is to be gained
by doing things another way

Not a great deal, except that you may forget to enable the cron job or
you may one day decide to change your session name. Simply installing a
plugin and then being able to forget about it would be nice. I don’t
really want to use backgroundrb though, after some investigation it
seems overkill. Think I’ll just go with your solution for now.

Jeroen

“Frederick C.” wrote:

to remove expired sessions? Any other suggestions?

For what it’s worth we just use a cron job that does find /tmp/sessions
-name ‘ruby_sess*’ -ctime +1 -exec rm -f {}
Not particularly beautiful but I’m not sure what there is to be gained
by doing things another way

Nice one-liner. However I can’t seem to get it to select files with
-ctime or -mtime
less than today (the run day).

find /tmp -name ‘ruby_sess*’ -maxdepth 1 -mtime n-whatever

If n-whatever is less than 1 I get the full list of files.
If n-whatever is >= +1 I dont get any match.

I only want to remove files that are at least one day old. What am I
missing?

I also wrote a ruby script recently that does what I want but this is
one of
the scripts that is having trouble running under cron (see my post with
subject
‘ruby script under cron’).

If anyone is interested in this script I can post it.

Long

Jon G. wrote:

I also wrote a ruby script recently that does what I want but this is one of
the scripts that is having trouble running under cron (see my post with subject
‘ruby script under cron’).

If anyone is interested in this script I can post it.

Long

You’re thinking it backwards. -ctime +5 would be files changed 5 days
ago. ‘man find’ is your friend.

-ctime n
Fileâ??s status was last changed n*24 hours ago. See the
comments
for -atime to understand how rounding affects the
interpretation
of file status change times.

I do that sometimes (thinking backwards :-). I did skim through the man
pages
but missed the ‘ago’ part. The n*24 is crucial here. The files I was
testing with are
less than 24 hours AGO, eventhough some were created yesterdays.

It is much clearer now. Thanks Jon.

Long

Long wrote:

I also wrote a ruby script recently that does what I want but this is one of
the scripts that is having trouble running under cron (see my post with subject
‘ruby script under cron’).

If anyone is interested in this script I can post it.

Long

You’re thinking it backwards. -ctime +5 would be files changed 5 days
ago. ‘man find’ is your friend.

-ctime n
Fileâ??s status was last changed n*24 hours ago. See the
comments
for -atime to understand how rounding affects the
interpretation
of file status change times.