ORGANIZAR SAÍDA DE ARQUIVOS [RESOLVIDO]

1. ORGANIZAR SAÍDA DE ARQUIVOS [RESOLVIDO]

Luiz Henrique
LuizCosta

(usa CentOS)

Enviado em 05/10/2019 - 15:47h

Fala galera, tudo bem?

Então, eu tenho um script onde ele reúne as informações de hardware e algumas outras e eu salvo isso em um TXT, porém, a solução que eu encontrei eu achei muito feia e porca, gostaria de saber se alguém consegue me da uma luz para deixar o código limpo segue Script:

#!/bin/bash
####################################################################
# Simples script para listar informacoes do sistema #
#Lista informacoes de: Data, Disco, Usuario, Memoria e Processador#
####################################################################

#Sistema para mostrar dados do sistema

#Aqui o sistema faz o requerimento de permissão para apresentar os dados e #testa a resposta do usuário

VELOCIDADEINTERNET="$(speedtest-cli | grep Download:)"

echo -e "Digite seu nome: \n"

read -r nome;

echo /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo .::.::.:: Data Atual ::.::.::. >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
date >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo =============================== >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo .::.::.:: Uso de Disco ::.::.::. >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
df -h | grep /sda >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo =============================== >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo .::.::.:: Usuário ::.::.::. >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
w >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo =============================== >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo .::.::.:: Memória ::.::.::. >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
free -m >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo =============================== >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo .::.::.:: Processador ::.::. >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
cat /proc/cpuinfo | grep "model name" | sed 's/model name : //' | sed -n '1p' >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo ============================== >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo .:.:.:.:.:.:.:.: Velocidade Internet .:.:.:.:.:.:.:.: >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo $VELOCIDADEINTERNET >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo ============================== >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt



  


2. MELHOR RESPOSTA

Marcelo Oliver
msoliver

(usa Debian)

Enviado em 06/10/2019 - 01:57h


LuizCosta escreveu:

Fala galera, tudo bem?

Então, eu tenho um script onde ele reúne as informações de hardware e algumas outras e eu salvo isso em um TXT, porém, a solução que eu encontrei eu achei muito feia e porca, gostaria de saber se alguém consegue me da uma luz para deixar o código limpo segue Script:

#!/bin/bash
####################################################################
# Simples script para listar informacoes do sistema #
#Lista informacoes de: Data, Disco, Usuario, Memoria e Processador#
####################################################################

#Sistema para mostrar dados do sistema

#Aqui o sistema faz o requerimento de permissão para apresentar os dados e #testa a resposta do usuário

VELOCIDADEINTERNET="$(speedtest-cli | grep Download:)"

echo -e "Digite seu nome: \n"

read -r nome;

echo /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo .::.::.:: Data Atual ::.::.::. >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
date >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo =============================== >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo .::.::.:: Uso de Disco ::.::.::. >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
df -h | grep /sda >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo =============================== >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo .::.::.:: Usuário ::.::.::. >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
w >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo =============================== >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo .::.::.:: Memória ::.::.::. >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
free -m >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo =============================== >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo .::.::.:: Processador ::.::. >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
cat /proc/cpuinfo | grep "model name" | sed 's/model name : //' | sed -n '1p' >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo ============================== >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo .:.:.:.:.:.:.:.: Velocidade Internet .:.:.:.:.:.:.:.: >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo $VELOCIDADEINTERNET >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt
echo ============================== >> /run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt

Dei uma "reduzida" . . .
Segue:
#!/bin/bash

clear;

tit[0]=".:.:.:.:.:.:: Data Atual ::.:.:.:.:.:."
tit[1]=".:.:.:.:.:.:: Uso de Disco ::.:.:.:.:.:."
tit[2]=".:.:.:.:.:.:: Usuário(s) ::.:.:.:.:.:."
tit[3]=".:.:.:.:.:.:: Memória ::.:.:.:.:.:."
tit[4]=".:.:.:.:.:.:: Processador ::.:.:.:.:.:."
tit[5]=".:.:.:.:.:.:: Velocidade Internet ::.:.:.:.:.:."

comando=("date" "df -h|grep /sda" "w" "free -m" "lscpu|sed -n \"s/Nome do modelo: \+//p\"" "./speedtest-cli|grep -E \"Download|Upload\"")
read -p " Digite seu nome: " nome;
DESTINO="/run/user/1000/gvfs/smb-share:server=192.168.10.252,share=programas/ProgramasEScripts/ConfigPc/Relatorios/Maquina_${nome}_$HOSTNAME.txt"
for ((n=0;n<${#comando[@]};n++));do
echo -e "${tit[$n]}\n" >> ${DESTINO};
eval ${comando[$n]} >> ${DESTINO};
echo -e " ================================================================== \n" >> ${DESTINO};
done

Importante: echo -e "\n$(lynx --dump goo.gl/a9KeFc|sed -nr '/^[ ]+Se/,/dou.$/p')\n"
Att.: Marcelo Oliver





Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts