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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

---<br />

Esempio 4-6. verifica del nome <strong>di</strong> dominio: wh, whois<br />

#!/bin/bash<br />

# ex18.sh<br />

Capitolo 4. Introduzione alle variabili ed ai parametri<br />

# Esegue una verifica ’whois nome-dominio’ su uno dei 3 server:<br />

# ripe.net, cw.net, radb.net<br />

# Inserite questo script - con nome ’wh’ - nel file /usr/local/bin<br />

# Sono richiesti i seguenti link simbolici:<br />

# ln -s /usr/local/bin/wh /usr/local/bin/wh-ripe<br />

# ln -s /usr/local/bin/wh /usr/local/bin/wh-cw<br />

# ln -s /usr/local/bin/wh /usr/local/bin/wh-radb<br />

E_NOARG=65<br />

if [ -z "$1" ]<br />

then<br />

echo "Utilizzo: ‘basename $0‘ [nome-dominio]"<br />

exit $E_NOARG<br />

fi<br />

# Verifica il nome dello script e interroga il server adeguato.<br />

case ‘basename $0‘ in # Oppure: case ${0##*/} in<br />

"wh" ) whois $1@whois.ripe.net;;<br />

"wh-ripe") whois $1@whois.ripe.net;;<br />

"wh-radb") whois $1@whois.radb.net;;<br />

"wh-cw" ) whois $1@whois.cw.net;;<br />

* ) echo "Utilizzo: ‘basename $0‘ [nome-dominio]";;<br />

esac<br />

exit $?<br />

---<br />

Il comando shift riassegna i parametri posizionali, spostandoli <strong>di</strong> una posizione verso sinistra.<br />

$1

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

Saved successfully!

Ooh no, something went wrong!