Last active
September 5, 2015 03:06
-
-
Save rajesh-gonuguntla/162b9ef3e92babebb4b5 to your computer and use it in GitHub Desktop.
How to clear tmp folder every x seconds or minutes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Step 1 Install tmpreaper | |
sudo apt-get install tmpreaper | |
/** | |
tmpreaper recursively searches for and removes files and empty | |
directories which haven’t been accessed for a given number of seconds. | |
Normally, it’s used to clean up directories which are used for | |
temporary holding space, such as "/tmp". Please read the WARNINGS | |
section of this manual. | |
*/ | |
// Create a shell script which executes tmpreaper | |
Create bash script (tmpcleaner.sh): | |
#!/bin/bash | |
tmpreaper --all --protect .localized 2s /tmp/ | |
// Step 3 Add executable permission on the script | |
chmod +x tmpcleaner.sh | |
// Step 4 Make it a cron job | |
crontab -e | |
Add to the crontab(add the variable PATH where is located tmpreaper): | |
PATH=/usr/sbin:/usr/bin:/sbin:/bin | |
* * * * * /tmpcleaner.sh | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment