Administration: Cleaning Up the WORK Library Automatically in UNIX

This post was kindly contributed by Business Intelligence Notes for SAS® BI Users - go there to comment and to read the full post.

blog work clean your work directory Administration: Cleaning Up the WORK Library Automatically in UNIX

Here is a quick tip for keeping the WORK library clean in a UNIX/Linux environment.  Most of the time SAS manages the cleanup process very well but sometimes orphaned processes can leave unwanted data lying around which can build up over time.  This tip is only applicable for UNIX or Linux environments.  Windows would have a similar approach with different commands.

 

Use a Shell Script for UNIX Heavy Lifting

This simple shell script will find all WORK directories created by SAS sessions and recursively remove everything within each directory older than a set time frame.  The joys of shell scripting!  icon smile Administration: Cleaning Up the WORK Library Automatically in UNIX


WORK
=/sas/work#!/bin/sh

find $WORK/ -mtime +3 -type f -exec rm -rf {} \;

exit 0

The WORK variable is set to the physical path of the WORK library on the compute server.  The number 3 represents the number of days since the file was last modified.  When this script is run, it initiates the find command which finds everything starting from the set directory with a last modified date older than 3 days, then forcibly removes everything within.  To prevent any permission problems, it should be run as ‘root’ or any other super user. 

Why Not Schedule It?

This shell script can be scheduled with cron or whatever scheduling system manages the server.  Personally I prefer cron because it just works!  More information about cron can be found here.

This post was kindly contributed by Business Intelligence Notes for SAS® BI Users - go there to comment and to read the full post.