Arquivo da tag: script

Script para redundancia de link

O Script a baixo é para quem possui dois links de internet, e quer que o alternativo entre em ação quando o principal cair. esse script fará isso automaticamente se colocado na crontab.

#!/bin/bash
#criar o arquivo se ele não existe
log=”/var/log/internet.log”
data=`date`

#link padrão sempre é o link2, nesta caso o link GVT

link1=”oi”
link2=”GVT”
gw_link1=”192.168.1.1″
gw_link2=”192.168.25.1″
destino_link1=”200.176.2.10″
destino_link2=”200.160.2.3″

route_link1=`/sbin/route -n |grep ^0.0.0.0 |grep $gw_link1 |wc -l`;
route_link2=`/sbin/route -n |grep ^0.0.0.0 |grep $gw_link2 |wc -l`;

#rota link1
/sbin/route add -host 200.176.2.10 gw $gw_link1
#rota link2
/sbin/route add -host 200.160.2.3 gw $gw_link2

if(ping -c 1 -w 2 $destino_link1 > /dev/null);then
echo “$data $destino_link1 $link1 OK” >> $log
/sbin/route del -host 200.176.2.10 gw $gw_link1
else
echo “$data $destino_link1 $link1 falhou” >> $log
fi;

if(ping -c 1 -w 2 $destino_link2 > /dev/null);then
echo “$data $destino_link2 $link2 OK” >> $log
/sbin/route del -host 200.160.2.3 gw $gw_link2
if [ $route_link2 = “0” ]; then
/sbin/route del default gw $gw_link1
/sbin/route add default gw $gw_link2
fi;

else
# clear
echo “$data $destino_link2 $link2 falhou” >> $log
echo “$data ativando link da $link1” >> $log
/sbin/route del default gw $gw_link2
/sbin/route add default gw $gw_link1
fi;

exit 0

Preenchendo formularios com curl

Vamos supor que você queira fazer aquele script para dar um reset no modem, pois bem, podemos usar o CURL para isso:

curl -u admin:gvt12345 -s -d “page=reset&action=submit” http://192.168.1.1/

onde: -uUSUARIO:SENHA
-s (submit)
-d (variaveis)
o ultimo parametro é a url do modem
Você pode usar esse comando para outros fins também, basta ser criativo 🙂

como remover todos os emails da mailq

postsuper -d ALL
ou se quiser remover uma mensagem especifica:
postsuper -d ID_DA_MENSAGEM

Script para remover emails da Mailq usando palavra

uso:
sh mailq.sh
vai perguntar quais emails você quer remover
vamos dizer que quer remover todos os emails enviados por fulano@teste.com.br
nesse caso, digite fulano@teste.com.br

#!/bin/bash
# Script para remover spam da mailq
####
c=0
echo “digite o prefixo (ex.: @yahoo.com)”
read prefix
while [ $c != 10 ]; do
for i in `mailq |grep $prefix |grep ^$c`; do `rm -rf /var/spool/postfix/active/$c/$i`; done;
for i in `mailq |grep $prefix |grep ^$c`; do `rm -rf /var/spool/postfix/defer/$c/$i`; done;
for i in `mailq |grep $prefix |grep ^$c`; do `rm -rf /var/spool/postfix/deferred/$c/$i`; done;
c=`expr $c + 1`
done;
# Apaga A
for i in `mailq |grep $prefix |grep ^A`; do `rm -rf /var/spool/postfix/defer/A/$i`; done;
for i in `mailq |grep $prefix |grep ^A`; do `rm -rf /var/spool/postfix/deferred/A/$i`; done;
for i in `mailq |grep $prefix |grep ^A`; do `rm -rf /var/spool/postfix/active/A/$i`; done;
## Apaga B
for i in `mailq |grep $prefix |grep ^B`; do `rm -rf /var/spool/postfix/defer/B/$i`; done;
for i in `mailq |grep $prefix |grep ^B`; do `rm -rf /var/spool/postfix/deferred/B/$i`; done;
for i in `mailq |grep $prefix |grep ^B`; do `rm -rf /var/spool/postfix/active/B/$i`; done;
## Apaga C
for i in `mailq |grep $prefix |grep ^C`; do `rm -rf /var/spool/postfix/defer/C/$i`; done;
for i in `mailq |grep $prefix |grep ^C`; do `rm -rf /var/spool/postfix/deferred/C/$i`; done;
for i in `mailq |grep $prefix |grep ^C`; do `rm -rf /var/spool/postfix/active/C/$i`; done;
## Apaga D
for i in `mailq |grep $prefix |grep ^D`; do `rm -rf /var/spool/postfix/defer/D/$i`; done;
for i in `mailq |grep $prefix |grep ^D`; do `rm -rf /var/spool/postfix/deferred/D/$i`; done;
### Apaga E
for i in `mailq |grep $prefix |grep ^E`; do `rm -rf /var/spool/postfix/defer/E/$i`; done;
for i in `mailq |grep $prefix |grep ^E`; do `rm -rf /var/spool/postfix/deferred/E/$i`; done;
for i in `mailq |grep $prefix |grep ^E`; do `rm -rf /var/spool/postfix/active/E/$i`; done;
# Apaga F
for i in `mailq |grep $prefix |grep ^F`; do `rm -rf /var/spool/postfix/defer/F/$i`; done;
for i in `mailq |grep $prefix |grep ^F`; do `rm -rf /var/spool/postfix/deferred/F/$i`; done;
for i in `mailq |grep $prefix |grep ^F`; do `rm -rf /var/spool/postfix/active/F/$i`; done;
# Apaga 1
for i in `mailq |grep $prefix |grep ^1`; do `rm -rf /var/spool/postfix/defer/1/$i`; done;
for i in `mailq |grep $prefix |grep ^1`; do `rm -rf /var/spool/postfix/deferred/1/$i`; done;
for i in `mailq |grep $prefix |grep ^1`; do `rm -rf /var/spool/postfix/active/1/$i`; done;
# Apaga 2
for i in `mailq |grep $prefix |grep ^2`; do `rm -rf /var/spool/postfix/defer/2/$i`; done;
for i in `mailq |grep $prefix |grep ^2`; do `rm -rf /var/spool/postfix/deferred/2/$i`; done;
for i in `mailq |grep $prefix |grep ^2`; do `rm -rf /var/spool/postfix/active/2/$i`; done;
# Apaga 3
for i in `mailq |grep $prefix |grep ^3`; do `rm -rf /var/spool/postfix/defer/3/$i`; done;
for i in `mailq |grep $prefix |grep ^3`; do `rm -rf /var/spool/postfix/deferred/3/$i`; done;
for i in `mailq |grep $prefix |grep ^3`; do `rm -rf /var/spool/postfix/active/3/$i`; done;
# Apaga 4
for i in `mailq |grep $prefix |grep ^4`; do `rm -rf /var/spool/postfix/defer/4/$i`; done;
for i in `mailq |grep $prefix |grep ^4`; do `rm -rf /var/spool/postfix/deferred/4/$i`; done;
for i in `mailq |grep $prefix |grep ^4`; do `rm -rf /var/spool/postfix/active/4/$i`; done;
# Apaga 5
for i in `mailq |grep $prefix |grep ^5`; do `rm -rf /var/spool/postfix/defer/5/$i`; done;
for i in `mailq |grep $prefix |grep ^5`; do `rm -rf /var/spool/postfix/deferred/5/$i`; done;
for i in `mailq |grep $prefix |grep ^5`; do `rm -rf /var/spool/postfix/active/5/$i`; done;

# Apaga 6
for i in `mailq |grep $prefix |grep ^6`; do `rm -rf /var/spool/postfix/defer/6/$i`; done;
for i in `mailq |grep $prefix |grep ^6`; do `rm -rf /var/spool/postfix/deferred/6/$i`; done;
for i in `mailq |grep $prefix |grep ^6`; do `rm -rf /var/spool/postfix/active/6/$i`; done;