Skip to content

Instantly share code, notes, and snippets.

@marcostolosa
Created April 18, 2019 13:13
Show Gist options
  • Save marcostolosa/a1a88801154666258001a4b110bba959 to your computer and use it in GitHub Desktop.
Save marcostolosa/a1a88801154666258001a4b110bba959 to your computer and use it in GitHub Desktop.
A sample shell script created to clean up cached files from lighttpd web server every 10 days. This script is directly created at /etc/cron.daliy/ directory.
```
#!/bin/bash
CROOT="/tmp/cachelighttpd/"
# Clean files every $DAYS
DAYS=10
# Web server username and group name
LUSER="lighttpd"
LGROUP="lighttpd"
# Okay, let us start cleaning as per $DAYS
/usr/bin/find ${CROOT} -type f -mtime +${DAYS} | xargs -r /bin/rm
# Failsafe
# if directory deleted by some other script just get it back
if [ ! -d $CROOT ]
then
/bin/mkdir -p $CROOT
/bin/chown ${LUSER}:${LGROUP} ${CROOT}
fi
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment