ronin

tiny-function-exec-log.sh

Apr 19th, 2012
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.30 KB | None | 0 0
  1. #!/bin/bash
  2. # package    http://sekysu.blogspot.com
  3. #
  4. # Gera log que pode ser útil para debugar funções escritas em shell scripts
  5. # file       tiny-function-exec-log.sh
  6. #
  7. # charset    UTF-8
  8. # endofline  Linux
  9. # since      2012-26-01 19:30 (GMT -03:00)
  10. # license    GPL v2.0
  11. #
  12. # system     GNU bash, version 3.1.17(2)-release i486 slackware 12.2
  13. # autor      Paulo Riceli Dias Lelis [ http://sekysu.blogspot.com  ]
  14. # more       http://sekysu.blogspot.com
  15. #
  16. # Variáveis
  17. # Nome do arquivo que irá receber o log de execução das funções
  18. SF_DBGF='SFDBG'
  19. # Funções
  20. function _debugFunction()
  21. {
  22.     # data e hora
  23.     _DT=$(date +%Y-%m-%d_%H:%M:%S)
  24.     # Arquivo de destino do log
  25.     _FL="/tmp/${SF_DBG_FL}${_DT}.txt"
  26.     # function name: ${FUNCNAME}
  27.     # line number: ${BASH_LINENO}
  28.     # params number: ${#@}
  29.     # params: ${@}
  30.     echo 'echo -e "'${_DT} : '${FUNCNAME} : ${BASH_LINENO} : ${#@} : ${@} : ${_MSGDBG[@]} " >> '${_FL}
  31. }
  32. #
  33. # Table test function
  34. function _tableTest()
  35. {
  36.     unset _MSGDBG
  37.     _MSGDBG[0]='start loop'
  38.     for i in {1..3}
  39.     do
  40.         _MSGDBG[$i]='\n\t - in the loop $i = '"$i"
  41.         echo -ne "$i"
  42.     done
  43.     echo
  44.     A=${#_MSGDBG[@]}
  45.     _MSGDBG[$A]="\nend of Loop"
  46.     eval $( _debugFunction $@ )
  47. }
  48. # Testes de mesa
  49. # Diretamente
  50. _tableTest 3 'bar' 'foo' 'beer'
  51. # Linha de comando
  52. _tableTest ${@}
  53. # Boa sorte!!!
Advertisement
Add Comment
Please, Sign In to add comment