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.

Appen<strong>di</strong>ce A. Script aggiuntivi<br />

# percorsi relativi - ci sono fin troppi link simbolici oggigiorno.<br />

# (la <strong>di</strong>rectori <strong>di</strong> default è quella <strong>di</strong> login <strong>di</strong> ftp)<br />

# -v abilita l’opzione verbose <strong>di</strong> ftp, per visualizzare tutte le risposte<br />

# provenienti dal server ftp.<br />

# -f fileremoto[:filelocale] nome da assegnare in locale al file remoto.<br />

# -m modello, effettua un mget con il modello specificato. Ricordate <strong>di</strong><br />

# applicare il quoting ai caratteri.<br />

# -c accede alla <strong>di</strong>rectory locale specificata.<br />

# Per esempio,<br />

# ftpget -h expo.lcs.mit.edu -d contrib -f xplaces.shar:xplaces.sh \<br />

# -d ../pub/R3/fixes -c ~/fixes -m ’fix*’<br />

# Ottiene xplaces.shar da ~ftp/contrib su expo.lcs.mit.edu, registrandolo come<br />

# xplaces.sh nella <strong>di</strong>rectory <strong>di</strong> lavoro corrente; recupera tutti i fixes da<br />

# ~ftp/pub/R3/fixes e li inserisce nella <strong>di</strong>rectory ~/fixes.<br />

# Ovviamente, è importante la sequenza delle opzioni, perché i<br />

# corrispondenti coman<strong>di</strong> vengono eseguiti da ftp in quell’or<strong>di</strong>ne.<br />

#<br />

# Mark Moraes (moraes@csri.toronto.edu), Feb 1, 1989<br />

#<br />

# ==> Questi commenti sono stati aggiunti dall’autore del libro.<br />

# PATH=/local/bin:/usr/ucb:/usr/bin:/bin<br />

# export PATH<br />

# ==> Le 2 righe precedenti dello script originale sono<br />

# probabilmente superflue.<br />

E_ERR_ARG=65<br />

FILETMP=/tmp/ftp.$$<br />

# ==> Crea un file temporaneo, il cui nome viene formato utilizzando<br />

# ==> l’id <strong>di</strong> processo dello script ($$).<br />

SITO=‘domainname‘.toronto.edu<br />

# ==> ’domainname’ simile a ’hostname’<br />

# ==> Andrebbe riscritto per un uso pià 1 generale.<br />

utilizzo="Utilizzo: $0 [-h hostremoto] [-d <strong>di</strong>rectoryremota]... \<br />

[-f filerem:filelocale]... [-c <strong>di</strong>rectorylocale] [-m modello] [-v]"<br />

opzftp="-i -n"<br />

opzverb=<br />

set -f # In modo da abilitare il globbing in -m<br />

set x ‘getopt vh:d:c:m:f: $*‘<br />

if [ $? != 0 ]; then<br />

echo $utilizzo<br />

exit $E_ERR_ARG<br />

fi<br />

shift<br />

trap ’rm -f ${FILETMP} ; exit’ 0 1 2 3 15<br />

# ==> Cancella il file temporaneo in caso <strong>di</strong> uscita anomala dallo script.<br />

echo "utente anonimo ${USER-gnu}@${SITO} > ${FILETMP}"<br />

# ==> Si usino gli apici (raccomandati per visualizzazioni complesse).<br />

633

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

Saved successfully!

Ooh no, something went wrong!