User sessions in Interchange are usually kept as files in the session/ directory (or inside a DBM database) for each catalog. Since session data is not deleted after sessions end (or timeout), periodic expiring needs to be set up to keep the session database or session files from growing too large, wasting disk space and slowing down directory lookups.

There's no worry that expiring will do any harm, because all our scripts only clean up unused sessions. Active users will not notice any change.

The simplest way to expire catalog's session files is to run expire -c CATALOG_NAME.

For convenience, there is also expireall script which reads all catalog entries in interchange.cfg and runs expire on them.

The expire script accepts a -r option which, when DBM sessions are used, tells the script to reorganize database files and recover lost disk space.

On a UNIX server, it's most useful to run expireall from crontab. As the Interchange user, run crontab -e to edit crontab data, and enter something like:

# once a day at 4:40 am
40 4 * * *    /PATH/TO/perl /PATH/TO/INTERCHANGE/bin/expireall -r


If a session saved search paging files in ScratchDir, they would not be deleted (see below for a solution).

When file-based sessions are used (no DBM), then you can use a custom script like this:

# expire_sessions.pl -- delete files 2 days old or older
# invoke as: /PATH/TO/perl expire_sessions.pl /PATH/TO/CATALOG/session/ ...

my @files;
my $dir;
foreach $dir (@ARGV) {
	 # just push files on the list
	 if (-f $dir) { push @files, $_; next; }

	 next unless -d $dir;

	 # get all the file names in the directory
	 opendir DIR, $dir or die "opendir $dir: $!\n";
	 push @files, ( map { "$dir/$_" } grep(! /^\.\.?$/, readdir DIR));

for (@files) {
	 unless (-f $_) {
			 warn "skipping $_, not a file.\n";
	 next unless -M $_ >= 2;
	 unlink $_ or die "unlink $_: $!\n";

This script can be adjusted as necessary. Refinements might include reading the file to "eval" the session reference and expire only customers who are not registered members.

If your files get chown-ed to root every day, then you probably used root's instead of Interchange user's crontab file. Either move the crontab to the Interchange user, or use su to swith users from the root account:

44 4 * * * su -c "/PATH/TO/INTERCHANGE/bin/expireall -r" IC_USERNAME

The above does not, however, clean temporary files from the ScratchDir directory. We don't often use the expire scripts any more. We just use a small standalone script clean_session_tmp:


for DIR in $*; do
  for i in session tmp; do
    if test -d "$DIR/$i"; then
      find $DIR/$i -type f -mmin +480 | xargs --no-run-if-empty rm
      find $DIR/$i -depth -type d -empty -mtime +2 | xargs --no-run-if-empty rmdir
      echo "$0: $DIR/$i doesn't exist.";

using a cron entry similar to:

44 0,4,8,12,16,20 * * * DIR/bin/clean_session_tmp /path/to/catdir1 /path/to/catdir2

DocBook! Interchange!