Artificial intelligent assistant

What is the right approach to purge /var/spool/abrt/ We want to automate the process of removing old directories from `/var/spool/abrt/`. We have RHEL machines - version 7.x. The known way is to do the following # systemctl stop abrtd # systemctl stop abrt-oops And we can remove all those directories and files with following rm command: # abrt-cli rm /var/spool/abrt/* And then start the services # systemctl start abrtd # systemctl start abrt-oops We want to simplify the deletion process as the following -- it will delete the directories that are older than 10 days from `/var/spool/abrt/` find /var/spool/abrt/ -type d -ctime +10 -exec rm -rf {} \; Is it a good alternative to purge the `/var/spool/abrt/` directory?

Here is my suggestion:

1) Create a shell script `/home/yael/purgeabrt.sh`


$ cat purgeabrt.sh

#!/bin/bash
set -e
function cleanup()
{
systemctl start abrtd
systemctl start abrt-oops
}

trap cleanup EXIT

systemctl stop abrtd
systemctl stop abrt-oops
find /var/spool/abrt/ -type d -ctime +10 -exec abrt-cli rm {} \;
cleanup


2) Run the script as **root** :


sudo crontab -e


Add the line:


*/5 * * * * bash /home/yael/purgeabrt.sh


in order to execute the `cron` job every 5 minutes.

Edit:

`set -e` will terminate the execution of the script if a command exits with a non-zero status.

`trap cleanup EXIT` will catch signals that may be thrown to the script and executes the cleanup code.

**Note:** The call to `cleanup` in the scripts last line is probably unnecessary (redundant) but improves readability of the code.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy da30344ee2730644112e3b348f8e3c13