Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index International Gentoo Users Forum italiano (Italian) Risorse italiane (documentazione e tools)
  • Search

[TIP] Script per smontare devices occupati

Forum riservato alla documentazione in italiano.

Moderator: ago

Post Reply
  • Print view
Advanced search
13 posts • Page 1 of 1
Author
Message
Dhaki
Guru
Guru
User avatar
Posts: 325
Joined: Wed Jun 16, 2004 3:23 pm
Location: Ticino - CH

[TIP] Script per smontare devices occupati

  • Quote

Post by Dhaki » Wed Dec 08, 2004 2:20 pm

Tradotto da questo topic. Mi sembrava una cosa interessante, spero non ci sia già qualcosa di simile :) .
--------------------------------------------------------------------
Ho deciso di condividere questo script nel caso che qualcuno abbia il mio stesso problema. Non potevo smontare alcune delle mie periferiche (hard drivers/ipod/...) perché erano sempre occupate. Ho quindi scritto uno shell script che può risultare molto utile per risolvere alcune di queste situazioni.

Prima lo script tenta di smontare il drive normalmente. Se fallisce, prova riavviando famd che é il problema più frequente. Se fallisce allora prova riavviando xinetd. Se fallisce ancora allora usa il comando "fuser -ki <il-tuo-drive-occupato>" che chiede se vuoi killare tutti i processi che stanno usando quella directory. Sii prudente con questo - sarebbe meglio sapere che processi stanno usando quella directory prima di killarli. Se fallisce anche questo, probabilmente é perché non puoi killare tutti i processi, quindi ti chiede se vuoi smontare pigramente (lazily, non sapevo come tradurlo esattamente) il device, rimuovendo il drive anche se ci sono processi che lo stanno usando. Non sono un esperto, quindi ditemi se ci sono miglioramenti da fare.

UTILIZZO:

Code: Select all

smartumount directory-da-smontare
ESEMPIO:

Code: Select all

smartumount /mnt/ipod
Ed ecco il codice:

Code: Select all

#!/bin/bash

if [ `whoami` != "root" ]; then
   echo "You must run this as root"
   exit
fi

dir=$1

# first try unmounting it without doing anything special
testumount=`umount $dir 2>&1`
if [ `echo $testumount | grep "not mounted" | wc -l` -gt 0 ]; then
   echo "$1 isn't mounted, exiting"
   exit
fi

if [ `echo $testumount | grep busy | wc -l` -gt 0 ]; then
   echo "Having trouble, checking famd..."
else
   echo "unmounted $dir without any trouble..."
   exit
fi

# check famd
if [ `ps -e |grep famd|wc -l` -gt 0 ]; then
   /etc/init.d/famd restart
   # try unmounting again
   if [ `umount $dir 2>&1 | wc -l` -gt 0 ]; then
      echo "I tried restarting famd, but that didn't work. checking xinetd"
   else
      echo "Unmounted $dir by restarting famd"
      exit
   fi
else
   echo "famd isn't running so it couldn't be that.."
fi


# check xinetd
if [ `ps -e | grep xinetd | wc -l` -gt 0 ]; then
   /etc/init.d/xinetd stop
   # try unmounting again
   if [ `umount $dir 2>&1 | wc -l` -lt 1 ]; then
      /etc/init.d/xinetd start
      echo "Unmounted $dir by restarting xinetd"
      exit
   fi
   /etc/init.d/xinetd start
   echo "I tried stopping xinetd, but that didn't work."

else
   echo "xinetd isn't running so it couldn't be that.."
fi

echo
echo "I'm going to list processes that are using the folder you are
trying to umount. Answer whether you'd like to kill them or not.
You should look up each process before you answer. use the
following command in a separate shell:"
echo
echo "   ps -e | grep <pid>"
echo
echo "where <pid> is the number of the process."
echo
fuser -ki $dir
echo
if [ `echo $testumount | grep busy | wc -l` -gt 0 ]; then
   echo "OK, this is the last resort. Do you want to umount the volume using "
   echo "the -l option? According to the umount man page -l means:"
   echo
   echo "   Lazy unmount. Detach the filesystem from the filesystem
   hierarchy now, and cleanup all references to the filesystem as
   soon as   it is not busy anymore.  (Requires kernel 2.4.11 or later.)"
   echo
   echo "Use -l option? (y\n)"
   read yn
   if [ $yn == "y" ]; then
      umount -l $dir
   else
      echo "OK. Sorry I couldn't help"
   fi
else
   echo "You're all good :)"
fi

exit 
Last edited by Dhaki on Sat Dec 18, 2004 9:21 pm, edited 2 times in total.
Top
Tiro
l33t
l33t
User avatar
Posts: 752
Joined: Fri Feb 14, 2003 9:37 am
Location: italy

  • Quote

Post by Tiro » Wed Dec 08, 2004 2:35 pm

grandioso! :)
Top
Wave2184
Apprentice
Apprentice
User avatar
Posts: 189
Joined: Sun Nov 02, 2003 9:51 am
Location: Roma

  • Quote

Post by Wave2184 » Wed Dec 08, 2004 3:48 pm

bel lavoro...era un idea che stava nel cassetto della mia scrivania da tempo ma il tempo è quello che è...e ne ho poco...

è un problema che mi capita spesso....

appena posso lo provo...

bel lavoro....
LINUX:sbav:

Powered by Gentoo 2004.2
Powered by Ubuntu 5.10
Top
fedeliallalinea
Administrator
Administrator
User avatar
Posts: 31985
Joined: Sat Mar 08, 2003 11:15 pm
Location: here
Contact:
Contact fedeliallalinea
Website

  • Quote

Post by fedeliallalinea » Wed Dec 08, 2004 4:15 pm

Aggiunto ai post utilissimi sezione tips
Questions are guaranteed in life; Answers aren't.

"Those who would give up essential liberty to purchase a little temporary safety,
deserve neither liberty nor safety."
- Ben Franklin
https://www.news.admin.ch/it/nsb?id=103968
Top
oRDeX
Veteran
Veteran
User avatar
Posts: 1325
Joined: Sun Oct 19, 2003 12:08 pm
Location: Italy
Contact:
Contact oRDeX
Website

  • Quote

Post by oRDeX » Wed Dec 08, 2004 4:22 pm

Molto utile direi..però penso una cosa: Questo script andrebbe usato solo in caso di emergenza, perchè se un device risulta occupato potrebbe essere utilizzato da qualche processo che magari al momento non viene in mente, e che se killato ci creerebbe problemi.
Quindi penso che bisognerà essere moltoooo prudenti nel suo utilizzo.
Top
stefanonafets
l33t
l33t
User avatar
Posts: 644
Joined: Mon Feb 10, 2003 2:32 pm

  • Quote

Post by stefanonafets » Wed Dec 08, 2004 6:42 pm

Domanda stupida, invece di usare

Code: Select all

 
if [ `whoami` != "root" ]; then
   echo "You must run this as root"
   exit
fi
nn sarebbe + giusto usare

Code: Select all

if [ "$UID" != "0" ]; then
     [...]
E' uguale? ()
registered Linux user number #411324
sed 's/ke/che/g'

<The Deployment Slave is initializing>
Top
Dhaki
Guru
Guru
User avatar
Posts: 325
Joined: Wed Jun 16, 2004 3:23 pm
Location: Ticino - CH

  • Quote

Post by Dhaki » Wed Dec 08, 2004 7:35 pm

stefanonafets wrote:Domanda stupida, invece di usare

Code: Select all

 
if [ `whoami` != "root" ]; then
   echo "You must run this as root"
   exit
fi
nn sarebbe + giusto usare

Code: Select all

if [ "$UID" != "0" ]; then
     [...]
E' uguale? ()
Bé... non penso siano molti a cambiare nome a root, quindi in pratica é la stessa cosa. Piu che altro penso sia una questione di sintassi, come per esempio:

Code: Select all

: > file
cat /dev/null > file
che sono la stessa cosa.
Questo script andrebbe usato solo in caso di emergenza, perchè se un device risulta occupato potrebbe essere utilizzato da qualche processo che magari al momento non viene in mente, e che se killato ci creerebbe problemi.
Questo é previsto, infatti:

Code: Select all

You should look up each process before you answer. use the
following command in a separate shell:"
echo
echo "   ps -e | grep <pid>" 
Ti consiglia di controllare i processi attivi prima di usare le maniere forti.
Top
FonderiaDigitale
Veteran
Veteran
User avatar
Posts: 1710
Joined: Thu Nov 06, 2003 4:28 am
Location: Rome, Italy
Contact:
Contact FonderiaDigitale
Website

  • Quote

Post by FonderiaDigitale » Wed Dec 08, 2004 10:28 pm

Dhaki wrote:Bé... non penso siano molti a cambiare nome a root, quindi in pratica é la stessa cosa. Piu che altro penso sia una questione di sintassi, come per esempio:

Code: Select all

: > file
cat /dev/null > file
che sono la stessa cosa.
beh oddio, il paragone stona: whoami e' un programma invocato dall'esterno, mentre UID e' una variabile d'ambiente a sola lettura!
Come disse un amico, i sistemisti sono un po' come gli artigiani per l'informatica :)
Top
Dhaki
Guru
Guru
User avatar
Posts: 325
Joined: Wed Jun 16, 2004 3:23 pm
Location: Ticino - CH

  • Quote

Post by Dhaki » Wed Dec 08, 2004 10:35 pm

FonderiaDigitale wrote:
Dhaki wrote:Bé... non penso siano molti a cambiare nome a root, quindi in pratica é la stessa cosa. Piu che altro penso sia una questione di sintassi, come per esempio:

Code: Select all

: > file
cat /dev/null > file
che sono la stessa cosa.
beh oddio, il paragone stona: whoami e' un programma invocato dall'esterno, mentre UID e' una variabile d'ambiente a sola lettura!
si infatti non ero molto sicuro di quello che calzasse a pieno... :oops: perdonate ciò che dissi...
Top
stefanonafets
l33t
l33t
User avatar
Posts: 644
Joined: Mon Feb 10, 2003 2:32 pm

  • Quote

Post by stefanonafets » Thu Dec 09, 2004 2:34 pm

Bè, una prova pratica (senza senso):

I script

Code: Select all

#!/bin/bash

if [ "$UID" != 0 ]; then
        echo "You arn't root"
fi
II script

Code: Select all

#!/bin/bash

if [ `whoami` != "root" ]; then
        echo "You arn't root"
fi
Proviamo i tempi:

Code: Select all

#time sh script1.sh
You arn't root

real    0m0.017s
user    0m0.000s
sys     0m0.010s

#time sh script2.sh
You arn't root

real    0m0.121s
user    0m0.000s
sys     0m0.040s
A voi (io nn sono abb. competente) l'ardua sentenza (perchè mai aspettare i posteri in questo caso? :D )
registered Linux user number #411324
sed 's/ke/che/g'

<The Deployment Slave is initializing>
Top
motaboy
Retired Dev
Retired Dev
User avatar
Posts: 1483
Joined: Mon Dec 15, 2003 2:38 pm

  • Quote

Post by motaboy » Thu Dec 09, 2004 4:15 pm

l'opzione -l non e' proprio eccezionale. in alcuni casi porta il tuo VFS in uno stato inconsistente. per esempio usandolo coi lettori cd, se dai l'umount -l e ne monti poi uno diverso mentre un processo stava ancora accedendo al vecchio si ha del garbage al posto dei nomi dei files e non e' possibile leggere nulla. Non so se e' un problema del mio kernel o se sia una cosa correggibile o meno.
...
Top
Dhaki
Guru
Guru
User avatar
Posts: 325
Joined: Wed Jun 16, 2004 3:23 pm
Location: Ticino - CH

  • Quote

Post by Dhaki » Fri Dec 10, 2004 8:22 pm

motaboy wrote:l'opzione -l non e' proprio eccezionale. in alcuni casi porta il tuo VFS in uno stato inconsistente. per esempio usandolo coi lettori cd, se dai l'umount -l e ne monti poi uno diverso mentre un processo stava ancora accedendo al vecchio si ha del garbage al posto dei nomi dei files e non e' possibile leggere nulla. Non so se e' un problema del mio kernel o se sia una cosa correggibile o meno.
Uhm... sarebbe meglio che metta un avvertimento nello script allora. Magari prima qualcuno potrebbe confermare/smentire con qualche prova empirica?

O altrimenti, avete altri metodi da segnalare??

EDIT: A proposito di supermount qualcuno sa darmi qualche info in piu? Questo script funziona lo stesso o ci sono accorgimenti da fare? Io non lo uso... quindi non saprei.
Top
rota
l33t
l33t
User avatar
Posts: 960
Joined: Wed Aug 13, 2003 9:22 pm

  • Quote

Post by rota » Fri Dec 10, 2004 9:20 pm

m... era ora che uscisse sta cosa,....... :wink:
http://users.gufi.org/~kame/visualizza. ... ti&id=2062
http://docs.sun.com
http://blackrhino.xrhino.com/main.php?page=home
Rota ama F E L I C I A tu iubesc
Top
Post Reply
  • Print view

13 posts • Page 1 of 1

Return to “Risorse italiane (documentazione e tools)”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic