Created
February 18, 2016 16:31
-
-
Save rayansostenes/52ce0e8e53b694b6e803 to your computer and use it in GitHub Desktop.
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 | |
# Envia o resultado de um comando para um tailbox `dialog` | |
# Parametros: | |
# $1 - titulo | |
# $2 - comando | |
pipe_command_to_tailbox_dialog() { | |
# Extraindo os parametros,sempre usando $1 seguido de `shift` | |
local title="$1"; shift | |
local command="$1"; shift | |
local output_file=`mktemp` | |
# stdbuf desativa o buffering do linux para um comando | |
(eval stdbuf -o L -e L $command) >& $output_file & | |
local -i bg_job=$! | |
# Exibindo o dialogo | |
dialog --title "$title ($command)" --tailbox $output_file 50 60 | |
# Checa se o processo iniciado anteriormente ainda está | |
# em execução se sim finaliza o processo | |
if [ -d /proc/$bg_job ]; then | |
kill $bg_job || kill -9 $bg_job >& /dev/null | |
fi | |
wait $bg_job | |
rm -f $output_file | |
clear | |
} | |
main() { | |
pipe_command_to_tailbox_dialog "Testando ping" "ping 127.0.0.1" | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment