getQuota

From Sepiola Wiki
Jump to: navigation, search
#! /bin/sh
#
# Copyright (C) 2011 stepping stone GmbH
#                    Switzerland
#                    http://www.stepping-stone.ch
#                    support@stepping-stone.ch
#
# Authors:
#  Michael Eichenberger <michael.eichenberger@stepping-stone.ch>
#  
# Licensed under the EUPL, Version 1.1 or – as soon they
# will be approved by the European Commission - subsequent
# versions of the EUPL (the "Licence");
# You may not use this work except in compliance with the
# Licence.
# You may obtain a copy of the Licence at:
#
# http://www.osor.eu/eupl
#
# Unless required by applicable law or agreed to in
# writing, software distributed under the Licence is
# distributed on an "AS IS" basis,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied.
# See the Licence for the specific language governing
# permissions and limitations under the Licence.
#
# $Id$
#
#
###############################################################################
# /bin/getQuota
###############################################################################
# Description:
# This script get's quota information out of the backupSizeFile
# to be displayed by Sepiola Online Backup Client
# using built-in let for calculations that is only capable of integer operations
# if value should be correctly rounded, floating-point is needed, use bc instead
###############################################################################
backupSizeFile="/etc/backupSize"
catCmd="/bin/cat"
quotaCmd="/usr/bin/quota"
quotaCmdOutput=`$quotaCmd -u $UID -w`
if [ "$?" -gt "1" ]; then
  exit 2
fi
 
# black magic begins here ;-)
# get 3rd line, get first four values of that, and finally, get rid of asterisks
blockQuotaValues=`echo "$quotaCmdOutput" | sed -e '1,2d' -e 's:\([^ ]\+\)\ \+\([^ ]\+\)\ \+\([^ ]\+\)\ \+\([^ ]\+\)\ \+.*:\2 \4:' -e 's:\*::g'`
i=0
for value in $blockQuotaValues; do
  let i=$i+1
  if [ "$i" == "1" ]; then
    let usedQuota=$value/1024
  elif [ "$i" == "2" ]; then
    # using built-in let at the moment, if should be rounded, use bc instead
    let totalQuota=$value/1024
  fi
  if [ $i -gt 2 ]; then
    exit 1
  fi
done
 
# Read Snapshots size from backupSize file
backupSize=`$catCmd $backupSizeFile`
if [ "$?" -eq "0" ]; then
  i=0
  for value in $backupSize; do
    let i=$i+1
    if [ $i -eq 3 ]; then
      snapshotsSize=$value;
    fi
  done
else
  exit 3
fi
 
# Calculate incoming size
let incomingSize=$usedQuota-$snapshotsSize
 
# Write out the values
echo "$totalQuota $incomingSize $snapshotsSize"

Back to Backup server set up

Personal tools
Namespaces

Variants
Actions
Navigation
Wiki
sepiola.org
Toolbox