Try a smarter usage script

This commit is contained in:
Micke Nordin 2025-05-23 11:49:10 +02:00
parent 37973d1f40
commit 63e14baea0

View file

@ -3,7 +3,6 @@
date=$(date "+%Y%m%d") date=$(date "+%Y%m%d")
hdate=$(date "+%Y-%m-%d") hdate=$(date "+%Y-%m-%d")
htime=$(date "+%H:%M") htime=$(date "+%H:%M")
remotes=$(rclone listremotes | grep -E '^sto[3-4]')
location="<%= @location %>" location="<%= @location %>"
if [[ -n "${1}" ]]; then if [[ -n "${1}" ]]; then
customer="${1}" customer="${1}"
@ -13,6 +12,11 @@ else
customer="<%= @customer %>" customer="<%= @customer %>"
allowmixedcustomers=no allowmixedcustomers=no
fi fi
yaml="/etc/hiera/data/common.yaml"
remotes=($(yq -r ".project_mapping.${customer}.prod.primary_project" ${yaml}))
remotes+=($(yq -r ".project_mapping.${customer}.prod.mirror_project" ${yaml}))
remotes+=($(yq -r ".project_mapping.${customer}.prod.assigned | .[].project" ${yaml}))
remotes+=($(yq -r ".project_mapping.${customer}.prod.assigned | .[].mirror_project" ${yaml}))
userjson=$(rclone cat --no-check-certificate --webdav-headers "Host,sunet.drive.sunet.se" --use-cookies "statistics:drive-server-coms/${location}/users.json") userjson=$(rclone cat --no-check-certificate --webdav-headers "Host,sunet.drive.sunet.se" --use-cookies "statistics:drive-server-coms/${location}/users.json")
users=$(echo ${userjson} | jq -r '.| keys | .[] | test("^((?!(^admin|^[_])).)*$")' | grep true | wc -l) users=$(echo ${userjson} | jq -r '.| keys | .[] | test("^((?!(^admin|^[_])).)*$")' | grep true | wc -l)
outfile1="${customer}-${date}-detailed.csv" outfile1="${customer}-${date}-detailed.csv"
@ -33,13 +37,13 @@ for remote in ${remotes}; do
status=${?} status=${?}
if [[ ${status} -ne 0 ]] && [[ "${allowmixedcustomers}" == "no" ]]; then if [[ ${status} -ne 0 ]] && [[ "${allowmixedcustomers}" == "no" ]]; then
((foundwrongcustomer += 1)) ((foundwrongcustomer += 1))
echo "Found ${project}${bucket} not maching ${customer}" echo "Found ${project}:${bucket} not maching ${customer}"
continue continue
elif [[ ${status} -ne 0 ]] && [[ "${allowmixedcustomers}" == "yes" ]]; then elif [[ ${status} -ne 0 ]] && [[ "${allowmixedcustomers}" == "yes" ]]; then
echo "Found ${project}${bucket} not maching ${customer}" echo "Found ${project}:${bucket} not maching ${customer}"
continue continue
fi fi
bucketinfo=$(rclone --config /root/.rclone.conf size "${project}${bucket}" --json) bucketinfo=$(rclone --config /root/.rclone.conf size "${project}:${bucket}" --json)
numfiles=$(jq '.count' <<<"${bucketinfo}") numfiles=$(jq '.count' <<<"${bucketinfo}")
((totalFiles += numfiles)) ((totalFiles += numfiles))
bytes=$(jq '.bytes' <<<"${bucketinfo}") bytes=$(jq '.bytes' <<<"${bucketinfo}")