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.

wget<br />

Capitolo 12. Filtri, programmi e coman<strong>di</strong> esterni<br />

L’utility wget rintraccia o scarica in modo non-interattivo file dal Web o da un sito ftp. Funziona<br />

bene in uno script.<br />

wget -p http://www.xyz23.com/file01.html<br />

# L’opzione -p o --page-requisite consente a wget <strong>di</strong> rintracciare tutti i file<br />

#+ necessari per visualizzare la pagina specificata.<br />

wget -r ftp://ftp.xyz24.net/~bozo/project_files/ -O $SAVEFILE<br />

# Segue l’opzione <strong>di</strong> ricorsività -r che recupera tutti i link<br />

#+ presenti sul sito specificato.<br />

Esempio 12-38. Ottenere una quotazione <strong>di</strong> borsa<br />

#!/bin/bash<br />

# quote-fetch.sh: Scarica una quotazione <strong>di</strong> borsa.<br />

E_NOPARAM=66<br />

if [ -z "$1" ] # Si deve specificare il titolo (sigla) da cercare.<br />

then echo "Utilizzo: ‘basename $0‘ co<strong>di</strong>ce_titolo"<br />

exit $E_NOPARAM<br />

fi<br />

co<strong>di</strong>ce_titolo=$1<br />

suffisso_file=.html<br />

# Cerca un file HTML, per cui bisogna usare un nome appropriato.<br />

URL=’http://finance.yahoo.com/q?s=’<br />

# Servizio finanziario <strong>di</strong> Yahoo, con suffisso <strong>di</strong> ricerca del titolo.<br />

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

-O ${co<strong>di</strong>ce_titolo}${suffisso_file} "${URL}${co<strong>di</strong>ce_titolo}"<br />

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

# Per vedere la cosa all’opera su http://search.yahoo.com:<br />

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

# URL="http://search.yahoo.com/search?fr=ush-news&p=${query}"<br />

# wget -O "$salvanomefile" "${URL}"<br />

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

# Registra un elenco <strong>di</strong> importanti URL.<br />

exit $?<br />

# Esercizi:<br />

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

#<br />

# 1) Aggiungete una verifica che confermi all’utente che esegue lo script<br />

304

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

Saved successfully!

Ooh no, something went wrong!