Monday, January 12, 2009

/tmp clean-up script modification, sessions dying with PHP

It seems there there was a little flaw in the script that I wrote a while ago, any PHP sessions on the server will timeout/die after 1 hour if you run that as an hourly cronjob, I have made a small modification to the script.

The only small modification is that now, it deletes all sess_* files that have not been accessed for 5 days therefore are probably just sitting there and never going to be used again, the rest remain deleted because it’s failed uploads/etc that will never be used again.


#!/bin/bash

# Change directory to /tmp
cd /tmp

# Clean up trash left by Gallery2
ls | grep '[0-9].inc*’ | xargs rm -fv

# Clean up PHP temp. session files
find /tmp -atime +5 -name ’sess_*’ -print | xargs rm -fv

# Clean up dead vBulletin uploads
ls | grep ‘vbupload*’ | xargs rm -fv

# Clean up failed php uploads
ls | grep ‘php*’ | xargs rm -fv

# Clean up failed ImageMagick conversions.
ls | grep ‘magick*’ | xargs rm -fv

Thanks!

No comments: