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.

fuser<br />

fi<br />

Capitolo 13. Coman<strong>di</strong> <strong>di</strong> sistema e d’amministrazione<br />

kill $t # Potrebbe servire ’kill -9’ per un processo testardo.<br />

# Qui sarebbe necessaria una verifica, per vedere se il processo ha<br />

#+ acconsentito ad essere terminato.<br />

# Forse un altro " t=‘pidof $processo‘ " oppure...<br />

# L’intero script potrebbe essere sostituito da<br />

# kill $(pidof -x nome_processo)<br />

# ma non sarebbe stato altrettanto istruttivo.<br />

exit 0<br />

Identifica i processi (tramite il PID) che hanno accesso ad un dato file, serie <strong>di</strong> file o <strong>di</strong>rectory. Può<br />

anche essere invocato con l’opzione -k che serve a terminare quei determinati processi. Questo ha<br />

interessanti implicazioni per la sicurezza, specialmente negli script che hanno come scopo quello <strong>di</strong><br />

evitare, agli utenti non autorizzati, l’accesso ai servizi <strong>di</strong> sistema.<br />

bash$ fuser -u /usr/bin/vim<br />

/usr/bin/vim: 3207e(bozo)<br />

bash$ fuser -u /dev/null<br />

/dev/null: 3009(bozo) 3010(bozo) 3197(bozo) 3199(bozo)<br />

fuser si rivela un’applicazione importante nel momento in cui si devono inserire o rimuovere<br />

fisicamente <strong>di</strong>spositivi <strong>di</strong> memorizzazione, come i CD ROM o le memorie flash USB. Talvolta<br />

umount fallisce con il messaggio d’errore device is busy. Questo sta ad in<strong>di</strong>care che qualche utente<br />

e/o processo(i) hanno accesso a quel <strong>di</strong>spositivo. Un fuser -um /dev/nome_<strong>di</strong>spositivo vi rivelerà il<br />

mistero, così che possiate terminare tutti i processi coinvolti.<br />

bash$ umount /mnt/driveusb<br />

umount: /mnt/driveusb: device is busy<br />

bash$ fuser -um /dev/driveusb<br />

/mnt/driveusb: 1772c(bozo)<br />

bash$ kill -9 1772<br />

365

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

Saved successfully!

Ooh no, something went wrong!