You can clear UNIX spool files periodically using the clearspool and deldirifempty (delete directory if empty) scripts.
The clearspool script deletes files that meet certain modification time criteria. If the spool files are completely cleared, the clearspool script calls deldirifempty. The deldirifempty script deletes empty directories within the spool directory.
If you run clearspool from a Telnet session, ensure you switch to the directory containing the spool files.
If you used the defaults when installing the agent, the spool directory is called spool.
The clearspool script assumes the spool directory is called spool in the current directory. If not, supply the full directory path name in the environment variable SPOOL.
Example: Create the clearspool and deldirifempty Scripts
The following are sample scripts. You can have other file maintenance procedures.
#! /bin/ksh
if [[ -z $SPOOL ]]
then
SPOOL=./spool
fi
find $SPOOL -type f -mtime +n -exec rm {} \;
find $SPOOL -depth -type d -exec /bin/ksh /script_path/deldirifempty {} \;
Specifies the age of the files to be deleted.
Note: Put this script in the same directory as the cybAgent binary. Otherwise, specify the full path for SPOOL. You cannot specify a symbolic-linked directory for the SPOOL path.
#!/bin/ksh
Dir=$(ls -A $1)
if [[ -z $Dir ]]
then
echo "deleting directory $1"
rmdir $1
else
echo "$1 is not empty"
fi
Example: Deleting Files Modified Yesterday or Earlier
In the following example, mtime is specified as +1 to delete files that were last modified at least one day ago. The clearspool script then calls the deldirifempty script, which deletes any empty spool subdirectories.
#!/bin/ksh
if [[ -z $SPOOL ]]
then
SPOOL=/AgentDirectory/spool
fi
find $SPOOL -type f -mtime +1 -exec rm {} \;
find $SPOOL -depth -type d -exec /bin/ksh /script_path/
deldirifempty {} \;
Note: $SPOOL cannot be symbolic-linked directories.
|
Copyright © 2010 CA.
All rights reserved.
|
|