|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: Jul 2002
Città: Provincia Tv
Messaggi: 1208
|
Fastidioso problema con uno script.
Ho trovato uno script per il firewall su internet. Purtroppo credo ci sia un
problema di encoding. Il simbolo di fine linea mi viene visualizzato come "^M" se provo a leggere il file con less. Come posso fare? Con altri programmi il file viene letto correttamente ( nano, kate, gedit ) pero' se provo a lanciarlo da console ottengo. echo: bad interpreter: No such file or directory/bin/bash Quasi sicuramente e' dovuto ad un problema di encoding. Che posso fare? |
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: Jul 2002
Città: Provincia Tv
Messaggi: 1208
|
Questo e' l'output che ottengo con cat -e firewall.sh
Codice:
#!/bin/bash^M#^M# Firewall personale by Benjamin (Mizar)^M# Modifyed by Ptah 31 May 2007^M# To be used in conjunction with lo.sh and wan.sh^M# lo.sh and wan.sh MUST NOT be renamed until done^M# ALSO in this file^M##################################################^M#########################^M# Definizione Variabili #^M#########################^MIPTABLES="/sbin/iptables"^MINITD="/home/myhome/Script/Firewall"^MLO="127.0.0.1"^M##############################^M# Definizione delle funzioni #^M# Nei file le spiegazioni #^M##############################^M##^M# $1 = nome interfaccia in ifconfig^M# $2 = ip interfaccia^M##^MinterfacciaLo()^M{^M $INITD/lo.sh $1 $IPTABLES^M}^MinterfacciaWan()^M{^M $INITD/wan.sh $1 $2 $IPTABLES^M}^M################################^M# Cosa devo fare del firewall? #^M################################^Mcase "$1" in^M start)^M ########################^M # Attivazione Firewall #^M ########################^M echo -n "Attivazione Firewall: "^M #################################^M # Caricamento Moduli del Kernel #^M #################################^M modprobe ip_tables^M modprobe iptable_nat^M modprobe ip_conntrack^M modprobe ip_conntrack_ftp^M modprobe ip_nat_ftp^M modprobe ipt_LOG^M modprobe ipt_MARK^M modprobe ipt_MASQUERADE^M modprobe ipt_REDIRECT^M modprobe ipt_REJECT^M modprobe ipt_TOS^M modprobe ipt_limit^M modprobe ipt_mac^M modprobe ipt_mark^M modprobe ipt_multiport^M modprobe ipt_state^M modprobe ipt_tos^M modprobe iptable_mangle^M #modprobe ipt_psd^M ############################^M # Reset delle impostazioni #^M ############################^M $IPTABLES -F^M $IPTABLES -F -t nat^M $IPTABLES -F -t mangle^M $IPTABLES -X^M $IPTABLES -X -t nat^M $IPTABLES -X -t mangle^M ################################^M # Impostazione Policy standard #^M ################################^M $IPTABLES -P INPUT DROP^M $IPTABLES -P FORWARD DROP^M $IPTABLES -P OUTPUT ACCEPT^M ###################################^M # Cerco le interfacce del sistema #^M ###################################^M CFGIFACE=`ifconfig | grep -i "Link encap:" | awk {'print $1'}`^M ###################################^M # Ciclo sui nomi delle Interfacce #^M ###################################^M for IFACE in $CFGIFACE^M do^M IFACEIP=`ifconfig | grep -i -A 1 "$IFACE" | grep "addr:" | awk -F ':' {'print $2'} | awk {'print $1'}`^M if [ $IFACEIP = $LO ] ; then^M interfacciaLo "$IFACE"^M else^M interfacciaWan "$IFACE" "$IFACEIP"^M fi^M done^M ;;^M stop)^M ###########################^M # Disattivazione Firewall #^M ###########################^M echo -n "Disattivazione Firewall: "^M $IPTABLES -F^M $IPTABLES -F -t nat^M $IPTABLES -F -t mangle^M $IPTABLES -X^M $IPTABLES -X -t nat^M $IPTABLES -X -t mangle^M $IPTABLES -P INPUT ACCEPT^M $IPTABLES -P FORWARD ACCEPT^M $IPTABLES -P OUTPUT ACCEPT^M echo "ok"^M ;;^M status)^M ##############################^M # Display stato del Firewall #^M ##############################^M echo -n "Regole attuali nel Firewall: "^M $IPTABLES -L^M ;;^M restart|reload)^M $0 stop^M $0 start^M ;;^M *)^M echo "Utilizzo: firewall {start|stop|restart|reload|status}" >&2^M exit 1^M ;;^Mesac^Mexit 0 Codice:
#!/bin/bash # # Firewall personale by Benjamin (Mizar) # Modifyed by Ptah 31 May 2007 # To be used in conjunction with lo.sh and wan.sh # lo.sh and wan.sh MUST NOT be renamed until done # ALSO in this file ################################################## ######################### # Definizione Variabili # ######################### IPTABLES="/sbin/iptables" INITD="/home/myhome/Script/Firewall" LO="127.0.0.1" ############################## # Definizione delle funzioni # # Nei file le spiegazioni # ############################## ## # $1 = nome interfaccia in ifconfig # $2 = ip interfaccia ## interfacciaLo() { $INITD/lo.sh $1 $IPTABLES } interfacciaWan() { $INITD/wan.sh $1 $2 $IPTABLES } ################################ # Cosa devo fare del firewall? # ################################ case "$1" in start) ######################## # Attivazione Firewall # ######################## echo -n "Attivazione Firewall: " ################################# # Caricamento Moduli del Kernel # ################################# modprobe ip_tables modprobe iptable_nat modprobe ip_conntrack modprobe ip_conntrack_ftp modprobe ip_nat_ftp modprobe ipt_LOG modprobe ipt_MARK modprobe ipt_MASQUERADE modprobe ipt_REDIRECT modprobe ipt_REJECT modprobe ipt_TOS modprobe ipt_limit modprobe ipt_mac modprobe ipt_mark modprobe ipt_multiport modprobe ipt_state modprobe ipt_tos modprobe iptable_mangle #modprobe ipt_psd ############################ # Reset delle impostazioni # ############################ $IPTABLES -F $IPTABLES -F -t nat $IPTABLES -F -t mangle $IPTABLES -X $IPTABLES -X -t nat $IPTABLES -X -t mangle ################################ # Impostazione Policy standard # ################################ $IPTABLES -P INPUT DROP $IPTABLES -P FORWARD DROP $IPTABLES -P OUTPUT ACCEPT ################################### # Cerco le interfacce del sistema # ################################### CFGIFACE=`ifconfig | grep -i "Link encap:" | awk {'print $1'}` ################################### # Ciclo sui nomi delle Interfacce # ################################### for IFACE in $CFGIFACE do IFACEIP=`ifconfig | grep -i -A 1 "$IFACE" | grep "addr:" | awk -F ':' {'print $2'} | awk {'print $1'}` if [ $IFACEIP = $LO ] ; then interfacciaLo "$IFACE" else interfacciaWan "$IFACE" "$IFACEIP" fi done ;; stop) ########################### # Disattivazione Firewall # ########################### echo -n "Disattivazione Firewall: " $IPTABLES -F $IPTABLES -F -t nat $IPTABLES -F -t mangle $IPTABLES -X $IPTABLES -X -t nat $IPTABLES -X -t mangle $IPTABLES -P INPUT ACCEPT $IPTABLES -P FORWARD ACCEPT $IPTABLES -P OUTPUT ACCEPT echo "ok" ;; status) ############################## # Display stato del Firewall # ############################## echo -n "Regole attuali nel Firewall: " $IPTABLES -L ;; restart|reload) $0 stop $0 start ;; *) echo "Utilizzo: firewall {start|stop|restart|reload|status}" >&2 exit 1 ;; esac exit 0 |
![]() |
![]() |
![]() |
#3 |
Senior Member
Iscritto dal: Feb 2006
Città: Parma
Messaggi: 3010
|
Comando sed per sotrituire il control M (^M) con il classico newline (\n):
Codice:
sed 's/^M/\n/' firewall.sh > firewall.sh.NEW
__________________
~Breve riferimento ai comandi GNU/Linux (ormai non molto breve...) |
![]() |
![]() |
![]() |
#4 |
Senior Member
Iscritto dal: Jul 2002
Città: Provincia Tv
Messaggi: 1208
|
Grazie e' gia' un'inizio. Purtroppo il comando che mi hai dato mi ha sostituito
solo il primo carriage return. |
![]() |
![]() |
![]() |
#5 |
Senior Member
Iscritto dal: Feb 2006
Città: Parma
Messaggi: 3010
|
Ah, quindi lo tratta come il newline, oppure si incarta sul newline sostituito... non l'avevo testato.
Prova con questo ciclo: Codice:
sed -e :a -e '$!N;s/^M/\n/;ta' firewall.sh > firewall.sh.NEW
__________________
~Breve riferimento ai comandi GNU/Linux (ormai non molto breve...) |
![]() |
![]() |
![]() |
#6 |
Senior Member
Iscritto dal: Jul 2002
Città: Provincia Tv
Messaggi: 1208
|
Bingo!
Grazie mille! ![]() |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 22:47.