On Tue, 20 Jul 2010, Mike Gabriel wrote:
earlier: contact@gmli.fr asked:
this night my server went off. Here is the reason :
# du -h --max-depth=1 . 856K ./C-test-50-1279548701_stDstartxfce4_dp24 ... snip 20 instances 8,0K ./ssh
Could someone tells me how to auto-clean client sessions ? :)
On Tue, 20 Jul 2010, Mike Gabriel wrote:
Is there a reason to keep the session folders of terminated sessions? It is nice to have some logs of terminated sessions but for production this is not really feasible...
Note in passing: It is curious that there is a './ssh/" rather than a /.ssh/ "invisible 'dotfile' directory"
There are diagnostic reasons to save such log files for perhaps a week --- it would seem that these should be in a per user subdirectory, such as ~/.logs/ or such, but ...
That to one side, it should be posible to 'age' and expire these using the 'find' command at startup
We initially see:
find path/to/logfiles -name "C-test*1279583278_st[DR]*" \
-a -exec rm {} \;
... I see the '/seconds since epoch value there which is useful to reduce ...
find path/to/logfiles -name "C-test*[0-9][0-9]{11}_st[DR]*" \
-a -exec rm {} \;
which says:
starting at the path indicated, and travelling down the filesystem, look for a file with a name of the pattern: "C-test*[0-9][0-9]{11}_st[DR]*" and when found, remove it. That needs a qualified, however, to save perhaps only the last seven day's matches, so that one can do diagnostics ...
so let's add a symbolic minimum retention time, which might be overridden by passing in a valie as an option (here: arg1), and put this into a script
#!/bin/sh
#
# age out old diagnostic matter, for the x2go project
#
# license: GPLv3+
# Copyright :R P Herrold <info at owlriver dot com>
#
# default number of days back to retain log files for
AGE=7
# and permit a command line number passed in to alter
# this
[ 0${1} -gt 0] && {
export AGE=${1}
}
#
LOGPATH="~"
#
find ${LOGPATH} -name "C-test*[0-9][0-9]{11}_st[DR]*"
-atime $AGE -a -exec rm {} \;
#
This is not immediately tested as I am away from my office at the moment, but it should work. Note that in testing the candidates for removal, oue might substitute: echo for the: rm in that command to see what would happen in a 'dry run'
Hope this helps ...
-- Russ herrold