shell-script-pt
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [shell-script] Usando o Sed


From: Tiago Barcellos Peczenyj
Subject: Re: [shell-script] Usando o Sed
Date: Wed, 20 Dec 2006 14:29:21 -0200

Humm

veja estas funções:

IPS=lista_ips.txt
desbloqueia_ip(){ # coloca no final do arquivo
        IP=${1}
        sed "/${IP}/d" -i ${IPS}
        echo $IP >> ${IPS}                        
}

bloqueia_ip(){ # coloca acima de desbloqueados
        IP=${1}
        sed "/${IP}/d" -i ${IPS}
        sed "s/.*desbloqueados/${IP}\n&/g" ${IPS} 
}

verifica_ip(){
        IP=${1}
        if grep -q ${IP} ${IPS} ; then
                sed  -n '/desbloqueados/,$p' ${IPS} | grep -q ${IP} && echo
'desbloqueado' || echo 'bloqueado'
        else
                echo "ip fora da lista"
        fi              
}

On 12/20/06, geovan127 <address@hidden> wrote:

Pessoal segue abaixo o meu script para escrever dentro de um arquivo,
 só que em um certo lugar, do arquivo por exemplo, quero inserir os
 ip´s depois de
 ######## bloqueados
 200.155.144.122
 255.255.244.255
 colocar ele aqui

 ou

 ####### desbloqueados
 200.155.144.155
 122.144.155.156
 coloca aqui

 Me falaram que com o sed dá, mas não consegui colocar esta sintaxe
 aqui, alguem pode me ajudar a melhorar isso? Agradeço a atenção de
 vcs!

 #!/bin/bash
 #
 dir_squid="/etc/squid"
 tmp="/tmp/squid"
 #
 trap "" 2 3
 trap "" 20

 if [ ! -d $tmp ]; then
         mkdir $tmp
 fi

 choice() {

 options=$(dialog --stdout --backtitle "Gerenciador de Bloqueio de
 IP´S / Internet e Informática" --title "Gerenciador de Bloque
 io de IP´S" \
         --radiolist "\nO que você deseja fazer?\n" 0 0 0 \
 1 "Bloquear um IP" off \
 2 "Desbloquear um IP" off \
 3 "Visualizar itens bloqueados" off \
 4 "Sair " off 2>&1)

 case $options in
 '')
 default
 ;;
 '1')
 add_IP
 ;;
 '2')
 rm_IP
 ;;
 '3')
 ver_bloqueados
 ;;
 '4')
 sair
 ;;
 *)
 ;;
 esac
 }

 default() {
 if [ $? = 0 ]; then
         dialog --title "Atenção" \
                 --msgbox "\n\nEscolha uma opção no menu principal" 9
 39
         choice
 else
         sair
 fi
 }

 add_IP() {
 dialog --title "Adicionando IP" \
         --inputbox "\nDigite o IP que vc quer deseja bloquear:" 11 34
 2>$tmp/word.txt
         if [ $? = 1 ]; then
                 choice
         fi
         if [ "`cat $tmp/word.txt`" == ""  ]; then
                 dialog --title "ERRO" \
                         --msgbox "\n\n    Nenhum IP foi digitada" 9 42
         else
                 if [ "`cat $tmp/word.txt`" = "`cat $tmp/word.txt |
 grep -f $dir_squid/access`" ]; then
                         dialog --title "Atenção" --msgbox "\n\n  Este
 IP já está bloqueado!" 9 40
                         choice
                 else
                         echo `cat $tmp/word.txt` >> $dir_squid/acess
                         dialog --title "IP adicionado com sucesso" \

 sair
 fi
 }

 add_IP() {
 dialog --title "Adicionando IP" \
         --inputbox "\nDigite o IP que vc quer deseja bloquear:" 11 34
 2>$tmp/wor
 d.txt
         if [ $? = 1 ]; then
                 choice
         fi
         if [ "`cat $tmp/word.txt`" == ""  ]; then
                 dialog --title "ERRO" \
                         --msgbox "\n\n    Nenhum IP foi digitada" 9 42
         else
                 if [ "`cat $tmp/word.txt`" = "`cat $tmp/word.txt |
 grep -f $dir_
 squid/access`" ]; then
                         dialog --title "Atenção" --msgbox "\n\n  Este
 IP já está
  bloqueado!" 9 40
                         choice
                 else
                         echo `cat $tmp/word.txt` >> $dir_squid/acess
                         dialog --title "IP adicionado com sucesso" \

 esac
 }

 default() {
 if [ $? = 0 ]; then
         dialog --title "Atenção" \
                 --msgbox "\n\nEscolha uma opção no menu principal" 9
 39
         choice
 else
         sair
 fi
 }

 add_IP() {
 dialog --title "Adicionando IP" \
         --inputbox "\nDigite o IP que vc quer deseja bloquear:" 11 34
 2>$tmp/word.txt
         if [ $? = 1 ]; then
                 choice
         fi
         if [ "`cat $tmp/word.txt`" == ""  ]; then
                 dialog --title "ERRO" \
                         --msgbox "\n\n    Nenhum IP foi digitada" 9 42
         else
                 if [ "`cat $tmp/word.txt`" = "`cat $tmp/word.txt |
 grep -f $dir_squid/access`" ]; then
                         dialog --title "Atenção" --msgbox "\n\n  Este
 IP já está bloqueado!" 9 40
                         choice
                 else
                         echo `cat $tmp/word.txt` >> $dir_squid/acess
                         dialog --title "IP adicionado com sucesso" \
                                 --msgbox "\n\nPressione <ENTER> para
 voltar ao menu principal" 9 51
                 fi
         fi
         choice
 }

 rm_IP() {
 dialog --title "Removendo IP" \
         --inputbox "\nDigite o IP que vc deseja deseja remover:" 11
 34 2>$tmp/rword.txt
         if [ $? = 1 ]; then
                 choice
         fi
         if [ "`cat $tmp/rword.txt`" == ""  ]; then
                 dialog --title "ERRO" \
                         --msgbox "\n\n    Nenhum IP foi digitado" 9 42
         else
                 if [ "`cat $tmp/rword.txt | grep -f
 $dir_squid/access.txt`" == "" ]; then
                         dialog --title "Atenção" --msgbox "\n\n  Este
 IP não está bloqueado!" 9 42




--
Tiago B Peczenyj
Linux User #405772

# cd /pub
# more beer


reply via email to

[Prev in Thread] Current Thread [Next in Thread]