Skip to content

Instantly share code, notes, and snippets.

@vadirajks
Created July 16, 2022 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vadirajks/cabaebb44a98b4690d7ead2d380c0b08 to your computer and use it in GitHub Desktop.
Save vadirajks/cabaebb44a98b4690d7ead2d380c0b08 to your computer and use it in GitHub Desktop.
deleting old whisper files
#!/bin/bash
delete_hours=3
delete_sec=$(( ($delete_hours*60)*60))
gcp_output_file=/tmp/app-gcp-list.txt
gcloud compute instances list --format="csv(name:sort=0,networkInterfaces.networkIP,zone:sort=1)" --filter="status=RUNNING AND labels.appname:app" |sed 's/\./_/g'>$gcp_output_file
[ ! $? -eq 0 ] && { echo >&2 "$gcp_output_file gcp command issue"; exit 1; }
[[ $(wc -l $gcp_output_file| awk '{print $1}') -lt 25 ]] && { echo >&2 "$gcp_output_file gcp command issue"; exit 1; }
for folder_list in /var/lib/carbon/whisper/asia-southeast1/app/autoscaling/vm /var/lib/carbon/whisper/asia-southeast1/app/static/vm ; do
[ $(echo $folder_list| awk -F/ '{print $(NF-1)}') == "static" ] && vm_type=static || vm_type=auto
for folder in $(ls $folder_list -1); do
if [ $(grep -c $vm_type.*$folder $gcp_output_file) -eq 0 ]; then
mtime=$(find $folder_list/$folder -type f -printf "%T@\n" | sort -nr | head -n 1)
if [ ${mtime%.*} -le $(( $(date +%s) - $delete_sec )) ]; then
rm -rf $folder_list/$folder
fi
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment