Skip to content

Instantly share code, notes, and snippets.

@peterkappus
Last active July 16, 2018 09:51
Show Gist options
  • Save peterkappus/ad950d0cd501a4caae4232bc73344327 to your computer and use it in GitHub Desktop.
Save peterkappus/ad950d0cd501a4caae4232bc73344327 to your computer and use it in GitHub Desktop.
Jenkins shell script job to Check the diskspace on a machine (specifically, see if the /usr mount is over 60% full)
# See if the /usr mount is over 60% full
# If so, exit with a status of 1. Otherwise, OK
df -h | grep "/usr" | grep -oP "\d+%" | grep -oP "\d+" | xargs -L1 -I{} bash -c 'if [ {} -ge 60 ]; then exit 1; else exit 0; fi'
# BONUS!
# remove any gz file older than 60 days which are type "file" (not directories)
find /path/to/logs/ -name "*.gz" -mtime +60 -type f -exec rm {} +
#zip any log file older than 10 days
find /path/to/logs/ -name "*.log" -mtime +10 -type f -exec gzip {} +
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment