-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog_v3.sh
More file actions
51 lines (38 loc) · 1.13 KB
/
Copy pathlog_v3.sh
File metadata and controls
51 lines (38 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# Nome do comando/script
command="$(basename "$0")"
# Diretório de log
log_dir="/tmp"
mkdir -p "$log_dir"
# Arquivos de log
timestamp="$(date +'%Y%m%d_%H%M%S')"
log_file="${log_dir}/${command}_${timestamp}.log"
log_error="${log_dir}/${command}_${timestamp}_error.log"
# Garantir arquivos e permissão
touch "$log_file" "$log_error"
chmod 644 "$log_file" "$log_error"
# Redirecionamento de saída
exec > >(tee -a "$log_file") 2> >(tee -a "$log_error" >&2)
# Função para log com timestamp
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*"
}
# Verificação de permissões
if [[ $EUID -ne 0 ]]; then
log "Este script precisa ser executado como root."
exit 1
fi
# Mensagem inicial
log "Iniciando script: $command"
log "Log de saída: $log_file"
log "Log de erro: $log_error"
# Exemplo de uso de comandos com log
log "Verificando interfaces de rede..."
ip -s addr show
log "Escaneando redes Wi-Fi..."
iw dev wlan0 scan | head -n 20 # Limita a saída para não poluir o log
log "Regras de firewall:"
iptables -L -v -n
log "Parâmetros do kernel:"
sysctl -a | grep net.ipv4.ip_forward
log "Script finalizado com sucesso."