Last active
October 31, 2015 01:43
-
-
Save lnoering/2730d36fe0ed851b7189 to your computer and use it in GitHub Desktop.
Calcular tempo de execução de crons.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# %s seconds since 1970-01-01 00:00:00 UTC | |
# %N nanoseconds (000000000..999999999) | |
# %m month (01..12) | |
# %d day of month (e.g., 01) | |
# %Y year | |
# %t a tab | |
# decrementar 1 da var( ${dias:+$(($dias-1))} ) caso tenha valor | |
# 10800 is timezone for brazil(gmt +3 hours) | |
if [ -z $1 ]; then | |
echo -e "Não foi informado o arquivo.\n$0 <Arquivo para executar>\n OU\n$0 <Arquivo para executar> <Arquivo log>" | |
exit 0; | |
fi | |
echo "#[ Inicio ]####################################################################" | |
datainicial=$(date +%s) | |
if [ -z $2 ]; then | |
echo "Resultado - " | |
echo -e $(bash $1) | |
else | |
echo "Resultado no Arquivo - "$2 | |
bash $1 >>$2 2>&1 | |
fi | |
datafinal=`date +%s` | |
soma=$(($datafinal - $datainicial)) | |
resultado=$((10800 + $soma)) | |
dias=$(date -d @$resultado +%d) | |
echo "=[ Estatísticas ]==============================================================" | |
echo "Data - "$(date +%d/%m/%Y) | |
echo "Horário - "$(date +%H:%M:%S) | |
echo "Usuário - "$(sh -c 'whoami') | |
echo "Duração - Dia(s) ${dias:+$(($dias-1))} Horas(H:M:S) "$(date -d @$resultado +%H:%M:%S) | |
echo "Arquivo - "$1 | |
echo "#[ FIM ]#######################################################################" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment