BASH
Configurare email
Configurare software
Hardware
Linux
Linux Mint
Linux Ubuntu
MIKROTIK
Pentru tonti
Securitate
VMWARE
Windows
bash :: functie bash pentru formatarea timpului petrecut intr-un proces
![]() CAMSCAPE SERVICES Cristian M. |
Title | Functie bash pentru formatarea timpului petrecut intr-un proces |
| Tags | bash, formatare timp, timp folosit | |
| Desc. | Functie bash pentru formatarea timpului petrecut intr-un proces | |
| Code | KBSH0002 v1.0 | |
| Date | 14 septembrie 2012 |
ELAPSED_DAYS days and ELAPSED_TIME (from START_DATE until END_DATE).
Util pentru rapoarte de activitate pe mail.
function DisplayTimeElapsed {
# Function that returns a string of the form
# "ELAPSED_DAYS days and ELAPSED_TIME (from START_DATE until END_DATE)"
#
# Param:
# - start date in seconds (from date +%s)
# - end date in seconds
#
# Return:
# - string of the form "ELAPSED_DAYS days and ELAPSED_TIME (from START_DATE until END_DATE)"
#
# CAMSCAPE SERVICES GPLv2
# http://www.camscape.ro
#
SECONDS_START=$1
SECONDS_END=$2
SECONDS_ELAPSED=$((SECONDS_END-SECONDS_START))
ELAPSED_DAYS=`date -u --date=@$SECONDS_ELAPSED +%d`
ELAPSED_DAYS=$((ELAPSED_DAYS-1))
ELAPSED_TIME=`date -u --date=@$SECONDS_ELAPSED +%H:%M:%S`
DATE_START=`date -u --date=@$SECONDS_START +"%d.%m.%Y %H:%M"`
DATE_END=`date -u --date=@$SECONDS_END +"%d.%m.%Y %H:%M"`
if [ $ELAPSED_DAYS -gt 0 ]; then
echo "$ELAPSED_DAYS days and $ELAPSED_TIME (from $DATE_START until $DATE_END)"
else
echo "$ELAPSED_TIME (from $DATE_START until $DATE_END)"
fi
}


