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.

Note<br />

# La riga precedente non funziona nella versione <strong>Bash</strong> 2.04.<br />

exec 7>> /var/log/event.log # Accoda in "event.log".<br />

log # Scrive la data e l’ora.<br />

else exec 7> /dev/null # Sopprime l’output.<br />

fi<br />

echo "DEBUG3: inizio" >&${DF_DEBUG3}<br />

ls -l >&5 2>&4 # comando1 >&5 2>&4<br />

echo "Fatto" # comando2<br />

Capitolo 16. Re<strong>di</strong>rezione I/O<br />

echo "invio mail" >&${DF_LOGEVENTI} # Scrive "invio mail" nel df nr.7.<br />

exit 0<br />

1. Un descrittore <strong>di</strong> file è semplicemente un numero che il sistema operativo assegna ad un file aperto<br />

per tenerne traccia. Lo si consideri una versione semplificata <strong>di</strong> un puntatore ad un file. È analogo ad<br />

un gestore <strong>di</strong> file del C.<br />

2. L’uso del descrittore <strong>di</strong> file 5 potrebbe causare problemi. Quando <strong>Bash</strong> crea un processo<br />

figlio, come con exec, il figlio ere<strong>di</strong>ta il df 5 (ve<strong>di</strong> la e-mail <strong>di</strong> Chet Ramey in archivio, SUBJECT:<br />

RE: File descriptor 5 is held open (http://www.geocrawler.com/archives/3/342/1996/1/0/1939805/)).<br />

Meglio non utilizzare questo particolare descrittore <strong>di</strong> file.<br />

408

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

Saved successfully!

Ooh no, something went wrong!