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,16 +3,20 @@
date=$(date "+%Y%m%d")
hdate=$(date "+%Y-%m-%d")
htime=$(date "+%H:%M")
remotes=$(rclone listremotes | grep -E '^sto[3-4]')
location="<%= @location %>"
if [[ -n "${1}" ]]; then
customer="${1}"
location="${customer}-<%= @environment %>"
location="${customer}-<%= @environment %>"
allowmixedcustomers=yes
else
customer="<%= @customer %>"
allowmixedcustomers=no
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")
users=$(echo ${userjson} | jq -r '.| keys | .[] | test("^((?!(^admin|^[_])).)*$")' | grep true | wc -l)
outfile1="${customer}-${date}-detailed.csv"
@ -33,13 +37,13 @@ for remote in ${remotes}; do
status=${?}
if [[ ${status} -ne 0 ]] && [[ "${allowmixedcustomers}" == "no" ]]; then
((foundwrongcustomer += 1))
echo "Found ${project}${bucket} not maching ${customer}"
echo "Found ${project}:${bucket} not maching ${customer}"
continue
elif [[ ${status} -ne 0 ]] && [[ "${allowmixedcustomers}" == "yes" ]]; then
echo "Found ${project}${bucket} not maching ${customer}"
echo "Found ${project}:${bucket} not maching ${customer}"
continue
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}")
((totalFiles += numfiles))
bytes=$(jq '.bytes' <<<"${bucketinfo}")