Last active
December 11, 2015 04:39
-
-
Save drbobbeaty/4546948 to your computer and use it in GitHub Desktop.
Nice script that cleans up stale deployment jars after 30 days, but _always_ preserves the last 5 so you can go back to any one of them if need be. Great for jruby and clojure projects where it's all in a single jar.
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
#!/bin/bash | |
# | |
# This script clears out all the "stale" jars that we no longer need. | |
# They have to be AT LEAST 30 days old, and we MUST keep the last 5. | |
# Other than that, they can go. | |
# | |
# | |
# Set upt he environment for this - as we do in all scripts | |
# | |
export PATH="/usr/local/bin:/usr/local/sbin:/usr/sbin:/sbin:$HOME/bin:$PATH" | |
export LANG="en_US.UTF-8" | |
# | |
# Jump right in... find out where this is meant to run, and get there | |
# | |
program=`basename $0` | |
cd | |
echo "Running $program from `pwd` on `hostname -f`..." | |
# find all the jar files with a creation date more than 30 days ago | |
oldJars=`find . -type f -name "*.jar" -ctime +30` | |
if [ "$oldJars" != "" ]; then | |
recentJars=`ls -rt ./*.jar | tail -6 | head -5` | |
for i in ${oldJars}; do | |
if [ "`echo ${recentJars} | grep $i`" = "" ]; then | |
echo "Removing $i" | |
rm $i | |
fi | |
done | |
fi | |
echo "vacuum of old deployments - complete" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment