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 />

file=$(wget -q $podcast -O - | tr ’\r’ ’\n’ | tr \’ \" | sed -n ’s/.*url="\([^"]*\)"<br />

for url in $file<br />

do<br />

echo $url >> temp.log<br />

if ! grep "$url" podcast.log > /dev/null<br />

then<br />

wget -q -P $<strong>di</strong>rdati "$url"<br />

fi<br />

done<br />

done < bp.conf<br />

# Trasforma i file <strong>di</strong> log creati <strong>di</strong>namicamente in file <strong>di</strong> log permanenti:<br />

cat podcast.log >> temp.log<br />

sort temp.log | uniq > podcast.log<br />

rm temp.log<br />

# Crea una playlist m3u:<br />

ls $<strong>di</strong>rdati | grep -v m3u > $<strong>di</strong>rdati/podcast.m3u<br />

exit 0<br />

Per terminare la sezione, un ripasso dei fondamenti . . . ed altro.<br />

Esempio A-31. Fondamenti rivisitati<br />

#!/bin/bash<br />

# basics-reviewed.bash<br />

# L’estenzione == *.bash == per i file è specifica <strong>di</strong> <strong>Bash</strong><br />

# Copyright (c) Michael S. Zick, 2003; Tutti i <strong>di</strong>ritti riservati.<br />

# Licenza: Utilizzabile in qualsiasi forma e per qualsiasi scopo.<br />

# Revisione: $ID$<br />

#<br />

# Dimostrazione commentata da M.C.<br />

# (autore de "<strong>Guida</strong> Avanzata <strong>di</strong> Scripting <strong>Bash</strong>")<br />

# Lo script è stato provato con le versioni <strong>Bash</strong> 2.04, 2.05a e 2.05b.<br />

# Potrebbe non funzionare con versioni precedenti.<br />

# Questo script <strong>di</strong>mostrativo genera il messaggio d’errore<br />

#+ --intenzionale-- "command not found". Ve<strong>di</strong> riga 407.<br />

# Chet Ramey, attuale manutentore <strong>di</strong> <strong>Bash</strong>, ha risolto i problemi qui<br />

#+ evidenziati. Le soluzioni verranno inserite in una prossima versione<br />

#+ <strong>di</strong> <strong>Bash</strong>.<br />

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

### Collegate con una pipe lo script a ’more’,###<br />

###+ per evitare che la visualizzazione ###<br />

727

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

Saved successfully!

Ooh no, something went wrong!