Eu tenho um script bash que gera outro script. Gostaria que a saída do eco fosse apenas para o arquivo, mas ele exibe na tela tudo o que eu tento (&> por exemplo). Aqui está o código:
while read line; do echo "sudo ufw deny from "$line" to any"; done < /home/photobcdev/hack-ban.txt >>/home/photobcdev/hack-ban.tmp
Funciona bem, mas exibe centenas de linhas sempre que é executado. Como fazer isso ficar quieto? Aqui está o script completo para informações contextuais:
#!/bin/bash
DATE=$(date +%Y-%m-%d--%H-%M)
echo $(date)" Suppression fichiers temporaires"
rm /home/photobcdev/hack.txt 2> /dev/null
rm /home/photobcdev/hack-ip.txt 2> /dev/null
rm /home/photobcdev/hack-ban.txt 2> /dev/null
rm /home/photobcdev/hack-ban.tmp 2> /dev/null
rm /home/photobcdev/hack-ban-diff.sh 2> /dev/null
echo $(date)" Génération liste IPs"
sudo grep 'Disconnected from invalid user' /var/log/auth.log>>/home/photobcdev/hack.txt
grep -o -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' /home/photobcdev/hack.txt>>/home/photobcdev/hack-ip.txt
sort -u /home/photobcdev/hack-ip.txt>>/home/photobcdev/hack-ban.txt
wc -l /home/photobcdev/hack-ban.txt
echo $(date)" Génération script ufw ban /IP"
#while read line; do echo "sudo ufw deny from "$line" to any"; done < /home/photobcdev/hack-ban.txt >>/home/photobcdev/hack-ban.tmp
while read line; do
echo "sudo ufw deny from $line to any" >> /home/photobcdev/hack-ban.tmp
done < /home/photobcdev/hack-ban.txt
echo $(date)" Création fichier final"
sort -u /home/photobcdev/hack-ban.tmp>>/home/photobcdev/hack-ban-${DATE}.sh
sort -u /home/photobcdev/hack-ban.sh
wc -l /home/photobcdev/hack-ban-${DATE}.sh
chmod +x /home/photobcdev/hack-ban-${DATE}.sh
grep -v -f /home/photobcdev/hack-ban.sh /home/photobcdev/hack-ban-${DATE}.sh >>/home/photobcdev/hack-ban-diff.sh
if [ -s /home/photobcdev/hack-ban-diff.sh ]; then
# Fichier non vide
echo $(date)" Fichier hack-ban-diff.sh généré"
wc -l /home/photobcdev/hack-ban-diff.sh
rm -f /home/photobcdev/hack-ban.sh 2> /dev/null
mv /home/photobcdev/hack-ban-${DATE}.sh /home/photobcdev/hack-ban.sh
chmod +x /home/photobcdev/hack-ban-diff.sh
echo $(date)" Exécution hack-ban-diff.sh"
/home/photobcdev/hack-ban-diff.sh
else
# Fichier vide
rm -f /home/photobcdev/hack-ban-diff.sh 2> /dev/null
rm -f /home/photobcdev/hack-ban-${DATE}.sh 2> /dev/null
echo $(date)" Pas de nouvelles IP détectées"
fi