Skip to content

Instantly share code, notes, and snippets.

@wflynny
Created January 24, 2019 20:05
Show Gist options
  • Save wflynny/6788e3b883c7ee7d1d280f13788f9af9 to your computer and use it in GitHub Desktop.
Save wflynny/6788e3b883c7ee7d1d280f13788f9af9 to your computer and use it in GitHub Desktop.
Check file lifetime stats on a GPFS
# I usually put this in my ~/.bash_aliases
# A portion of our GPFS storage removes files after 21 days of creation.
# `stat` does not show creation time, so we have to resort to parsing the
# output of `mmlsattr`
ftime() {
# Usage:
# ftime path/to/file
#
# Outputs:
# File [path/to/file] has lived for 18:04:52.
# File [path/to/file] has roughly 3 days left alive.
# File [path/to/file] will die on 2019/01/25 @ 11:30.
#
# Notes:
# may or may not work with directories, e.g. `ftime path/to/directories`
# will not work with globs, e.g. `ftime path/to/*`
if [[ $# -ne 1 ]]; then
>&2 echo "Specify a file!"
exit 1
fi
if [[ "$(readlink -f ${1} | cut -d/ -f2)" != "gpfs" ]]; then
>&2 echo "File [${1}] must be on /fastscratch/"
exit 1
fi
mmlsattr=/usr/lpp/mmfs/bin/mmlsattr
birth_time=$(mmlsattr -L $1 | grep creat | cut -d: -f2-)
birthday=$(date -d "${birth_time}" '+%s')
now=$(date '+%s')
expiredays=21
datediff=$((now-birthday))
daysalive=$((datediff/86400))
daysleft=$((expiredays - daysalive))
deathday=$(date -d@"$((birthday+expiredays*86400))" '+%Y/%m/%d @ %H:%M')
echo "File [$1] has lived for ${daysalive}:$(date -u -d@${datediff} +%H:%M)."
echo "File [$1] has roughly ${daysleft} days left alive."
echo "File [$1] will die on ${deathday}."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment