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.

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

echo binary >> ${FILETMP}<br />

for i in $* # ==> Elaborazione degli argomenti passati da riga <strong>di</strong> comando.<br />

do<br />

case $i in<br />

-v) opzverb=-v; echo hash >> ${FILETMP}; shift;;<br />

-h) hostrem=$2; shift 2;;<br />

-d) echo cd $2 >> ${FILETMP};<br />

if [ x${opzverb} != x ]; then<br />

echo pwd >> ${FILETMP};<br />

fi;<br />

shift 2;;<br />

-c) echo lcd $2 >> ${FILETMP}; shift 2;;<br />

-m) echo mget "$2" >> ${FILETMP}; shift 2;;<br />

-f) f1=‘expr "$2" : "\([^:]*\).*"‘; f2=‘expr "$2" : "[^:]*:\(.*\)"‘;<br />

echo get ${f1} ${f2} >> ${FILETMP}; shift 2;;<br />

--) shift; break;;<br />

esac<br />

# ==> ’lcd’ e ’mget’ sono coman<strong>di</strong> ftp. Ve<strong>di</strong> "man ftp" . . .<br />

done<br />

if [ $# -ne 0 ]; then<br />

echo $utilizzo<br />

exit $E_ERR_ARG<br />

# ==> "exit 2" nell’originale, cambiato per uniformarsi allo standard.<br />

fi<br />

if [ x${opzverb} != x ]; then<br />

opzftp="${opzftp} -v"<br />

fi<br />

if [ x${hostrem} = x ]; then<br />

hostrem=prep.ai.mit.edu<br />

# ==> Mo<strong>di</strong>ficatelo per il sito ftp appropriato.<br />

fi<br />

echo quit >> ${FILETMP}<br />

# ==> Tutti i coman<strong>di</strong> salvati nel file temporaneo.<br />

ftp ${opzftp} ${hostrem} < ${FILETMP}<br />

# ==> Il file temporaneao viene elaborato in modalità batch da ftp.<br />

rm -f ${FILETMP}<br />

# ==> Infine, il file temporaneo viene cancellato<br />

# (potreste desiderare registralo in un file <strong>di</strong> log).<br />

# ==> Esercizi:<br />

# ==> --------<br />

# ==> 1) Aggiungete le verifiche d’errore.<br />

# ==> 2) Aggiungete altri fronzoli.<br />

+<br />

Antek Sawicki ha fornito lo script seguente che fa un uso molto intelligente degli operatori <strong>di</strong><br />

sostituzione <strong>di</strong> parametro <strong>di</strong>scussi in la Sezione 9.3.<br />

634

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

Saved successfully!

Ooh no, something went wrong!