11.04.2013 Views

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

iwconfig<br />

route<br />

# ...<br />

# Controlla se la rete è attiva.<br />

[ ${NETWORKING} = "no" ] && exit 0<br />

[ -x /sbin/ifconfig ] || exit 0<br />

# ...<br />

Capitolo 13. Coman<strong>di</strong> <strong>di</strong> sistema e d’amministrazione<br />

for i in $interfaces ; do<br />

if ifconfig $i 2>/dev/null | grep -q "UP" >/dev/null 2>&1 ; then<br />

action "L’interfaccia $i non è attiva: " ./ifdown $i boot<br />

fi<br />

# L’opzione "-q" <strong>di</strong> "grep", che è una specifica GNU, significa<br />

#+ "quiet", cioè, non produce output.<br />

# Quin<strong>di</strong>, re<strong>di</strong>rigere l’output in /dev/null non è strettamente necessario.<br />

# ...<br />

echo "Attualmente sono attivi questi <strong>di</strong>spositivi:"<br />

echo ‘/sbin/ifconfig | grep ^[a-z] | awk ’{print $1}’‘<br />

# ^^^^^<br />

# si dovrebbe usare il quoting per evitare il globbing.<br />

# Anche le forme seguenti vanno bene.<br />

# echo $(/sbin/ifconfig | awk ’/^[a-z]/ { print $1 })’<br />

# echo $(/sbin/ifconfig | sed -e ’s/ .*//’)<br />

# Grazie, S.C. per i commenti aggiuntivi.<br />

Ve<strong>di</strong> anche Esempio 29-6.<br />

È il comando pre<strong>di</strong>sposto per la configurazione <strong>di</strong> una rete wireless. È l’equivalente wireless del<br />

precedente ifconfig, .<br />

Mostra informazioni, o permette mo<strong>di</strong>fiche, alla tabella <strong>di</strong> routing del kernel.<br />

bash$ route<br />

Destination Gateway Genmask Flags MSS Window irtt Iface<br />

pm3-67.bozosisp * 255.255.255.255 UH 40 0 0 ppp0<br />

127.0.0.0 * 255.0.0.0 U 40 0 0 lo<br />

default pm3-67.bozosisp 0.0.0.0 UG 40 0 0 ppp0<br />

368

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!