Created
February 18, 2023 01:00
-
-
Save dhulihan/4c65e868851660fb0d8bfa2d059e7967 to your computer and use it in GitHub Desktop.
Kill Old Tmux Sessions
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
# this script lists old tmux sessions and kills them to free up resources | |
TOO_OLD_THRESHOLD_SECS=604800 # 7 days | |
NOW=$((`date +%s`)) | |
tmux ls -F '#{session_name} #{session_activity}' | while read -r LINE; do | |
SESSION_NAME=$(echo $LINE | awk '{print $1}') | |
LAST_ACTIVITY=$(echo $LINE | awk '{print $2}') | |
LAST_ACTIVITY_SECS_ELAPSED=$(($NOW - $LAST_ACTIVITY)) | |
if [[ "$LAST_ACTIVITY_SECS_ELAPSED" -gt "$TOO_OLD_THRESHOLD_SECS" ]]; then | |
echo "${SESSION_NAME} is ${LAST_ACTIVITY_SECS_ELAPSED}s inactive, killing..." | |
tmux kill-session -t ${SESSION_NAME} | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment