Anyone got a quick code snippet I can add to my crontab? Since Rails doesn''t do any housekeeping, my /tmp directory just keeps getting fatter and fatter. I found this useless snippet in the Agile book: find /tmp/ -name ''ruby_sess*'' -ctime +12h -delete Fedora Linux complains about the ''h'' in 12h, then if you remove the ''h'' he complains about the ''-delete'' part too which doesn''t even seem to exist in the man page for find. Anyone got a snippet that actually works? ;-) Sean -- Posted via http://www.ruby-forum.com/.
Sean Schertell wrote:> Anyone got a snippet that actually works? ;-)Here is what I use on my Debian box: find /tmp/ -name "ruby_sess*" -cmin +600 -exec rm {} \; Works for me :) -- Posted via http://www.ruby-forum.com/.
On Sat, Dec 17, 2005 at 06:22:52AM +0100, Sean Schertell wrote:> Anyone got a quick code snippet I can add to my crontab? Since Rails > doesn''t do any housekeeping, my /tmp directory just keeps getting fatter > and fatter. I found this useless snippet in the Agile book: > > find /tmp/ -name ''ruby_sess*'' -ctime +12h -delete > > Fedora Linux complains about the ''h'' in 12h, then if you remove the ''h''I get a similar warning with the find in Ubuntu Breezy (4.2.22). Considering that version was released from the GNU project (according to it''s timestamp in the FTP directory) in June, I''m curious as to what version of find was being used in the Rails book.> he complains about the ''-delete'' part too which doesn''t even seem to > exist in the man page for find.This option exists in my manpage, and seems to work fine. I suspect Fedora''s find may be a little out of date.> Anyone got a snippet that actually works? ;-)find /tmp/ -name ''ruby_sess*'' -cmin +$((12*60)) -exec rm -f ''{}'' \; should be equivalent and be fairly portable across distros (modulo any shell unhappiness with the $((12*60)) construct, which may be a bashism). - Matt _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Matthew Palmer wrote:> On Sat, Dec 17, 2005 at 06:22:52AM +0100, Sean Schertell wrote: >> Anyone got a quick code snippet I can add to my crontab? Since Rails >> doesn''t do any housekeeping, my /tmp directory just keeps getting fatter >> and fatter. I found this useless snippet in the Agile book: >> >> find /tmp/ -name ''ruby_sess*'' -ctime +12h -delete >> >> Fedora Linux complains about the ''h'' in 12h, then if you remove the ''h'' > > I get a similar warning with the find in Ubuntu Breezy (4.2.22). > Considering that version was released from the GNU project (according to > it''s timestamp in the FTP directory) in June, I''m curious as to what > version > of find was being used in the Rails book. > >> he complains about the ''-delete'' part too which doesn''t even seem to >> exist in the man page for find. > > This option exists in my manpage, and seems to work fine. I suspect > Fedora''s find may be a little out of date. > >> Anyone got a snippet that actually works? ;-) > > find /tmp/ -name ''ruby_sess*'' -cmin +$((12*60)) -exec rm -f ''{}'' \; > > should be equivalent and be fairly portable across distros (modulo any > shell > unhappiness with the $((12*60)) construct, which may be a bashism). > > - MattAs usual, Rails community to the rescue. Both snippets seem to work just fine. Thank you! Sean -- Posted via http://www.ruby-forum.com/.
On Saturday 17 December, Matthew Palmer wrote:> Considering that version was released from the GNU project (according to > it''s timestamp in the FTP directory) in June, I''m curious as to what version > of find was being used in the Rails book.The screenshots in the book give it away; it was most likely a version of find for BSD (the screenshots indicate that the authors like Macs). -- Graham
On Sat, Dec 17, 2005 at 10:33:39AM -0500, Graham Ashton wrote:> On Saturday 17 December, Matthew Palmer wrote: > > > Considering that version was released from the GNU project (according to > > it''s timestamp in the FTP directory) in June, I''m curious as to what version > > of find was being used in the Rails book. > > The screenshots in the book give it away; it was most likely a version of > find for BSD (the screenshots indicate that the authors like Macs).An excellent point, and one that I hadn''t considered. Makes perfect sense, too. Time to file a bug report on GNU find to add the multiplier suffixes. <grin> - Matt
Brad Daily wrote:> Sean Schertell wrote: >> Anyone got a snippet that actually works? ;-) > > Here is what I use on my Debian box: > > find /tmp/ -name "ruby_sess*" -cmin +600 -exec rm {} \; > > Works for me :)Wouldn''t you want to use -amin instead of -cmin? (access vs. created) In other words, you probably want to delete stale session files that haven''t been used in a while rather than just deleting files that were created a while ago. Otherwise you risk dumping people''s sessions who frequent the site out from under them while they are in use. -- Posted via http://www.ruby-forum.com/.
Phil Edelbrock wrote:> > > Wouldn''t you want to use -amin instead of -cmin? (access vs. created) >BTW- We''ve got this thrown in a script file in /etc/cron.daily/ on our RedHat Enterprise server: find /tmp/ -name ''ruby_sess*'' -atime +4 -exec rm {} \; It removes session files that haven''t been accessed for over 4 days. Phil -- Posted via http://www.ruby-forum.com/.
Hi, I probably should have made this post a new topic. But is there a good way to clear sessions in general? Should one always rely on a cron job? Thanks, Ram. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
works for me: class Cronjobs def self.clear_sessions Session.delete_all(["updated_at <= ?", Time.now.yesterday.strftime(''%Y-%m-%d'')]) end end and then in your crontab: 20 0 * * * /path/to/rails/app/current/script/runner ''Cronjobs.clear_sessions;'' -e production ed On 1/10/07, Ram <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > > Hi, > > I probably should have made this post a new topic. But > is there a good way to clear sessions in general? Should > one always rely on a cron job? > > Thanks, > Ram. > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---