Try a smarter usage script
This commit is contained in:
parent
37973d1f40
commit
63e14baea0
1 changed files with 9 additions and 5 deletions
|
@ -3,16 +3,20 @@
|
||||||
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}"
|
||||||
location="${customer}-<%= @environment %>"
|
location="${customer}-<%= @environment %>"
|
||||||
allowmixedcustomers=yes
|
allowmixedcustomers=yes
|
||||||
else
|
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}")
|
||||||
|
|
Loading…
Add table
Reference in a new issue