|
|
#1 |
|
MVP
Join Date: Apr 2002
Location: UK
Posts: 1,212
|
can anyone help with this "problem"?
Hi,
I’m trying to work out how to use terminal to mount a previously unmounted disk. The reason I want to do this is that I have an external firewire drive that I use for backup purposes through a backup script run via cron at 6am. The backup works fine but the rest of time I have problems with the drive in that after it spins down it takes up to 10 seconds to spin up again. This is irritating because whenever I select column view in the finder the window doesn’t appear until after the drive has spun up. It also spins up at other times, though I’ve not been able to work out exactly why. I’ve discovered disktool but have a problem with it. Using: disktool –p disk2s9 0 unmounts the disk without a problem, but: disktool –m disk2s9 doesn’t quit; i.e. If you run this in terminal you need to enter ctrl-C to quit it. Now, if I run this command as a cron job the process keeps running, and if I run it twice I have two occurrences running, and so on. I don’t imagine that this is a great problem but it is “untidy” and means that I need to manually kill these occurrences every once in a while. So I wondered if i) anyone knew how to use/configure disktool and get it to quit after mounting the disk (but from the research I've done I suspect not), or ii) can anyone think of a way to get it to quit. Two possible solutions occured to me but I don't know how to do either of them. First: is it possible to construct a single line command that can be run via cron that first runs the disktool -m command and then quits it. I've come across the pipe command - "|" - but have no idea if it works (or how to use it) in these sort of circumstances. Second: I assume there must be a way of killing a particular process that I could run as a separate cron job, but again, I don't know how to do it. I know that "kill pid" would work but I don't know how to get the pid in the first instance, at least not so I can do this via cron. Any help, suggestions, and/or comments welcome.
__________________
chromasia G4/800, OS 10.3.x, 1.25GB RAM, 2x80GB HD, 60GB firewire, Geforce4MX, Iiyama VMpro 455+413 Goldtouch keyboard, Cirque EasyCat trackpad, D-Link DSL-604+ |
|
|
|
|
|
#2 |
|
League Commissioner
Join Date: Jan 2002
Posts: 5,536
|
it is unfortunate that disktools -m doesn't quit properly (here, too). one suggestion might be to fork it as a background job a la command & then sleep for 10 seconds and when the parent process dies, it should tear down any background jobs with it.
comprende? you'll want to test that pretty good. |
|
|
|
|
|
#3 |
|
MVP
Join Date: Apr 2002
Location: UK
Posts: 1,212
|
>it is unfortunate that disktools -m doesn't quit properly (here, too). one suggestion might be to fork it as a background job a la command & then sleep for 10 seconds and when the parent process dies, it should tear down any background jobs with it.
>comprende? >you'll want to test that pretty good. Thanks for taking the time to answer but I didn't understand a word of that I don't know what "fork it as a background job a la command" means, nor how to sleep for 10 seconds, nor do I understand why the parent process will die. While my question might have sounded like I know what I'm talking about - clearly I don't
__________________
chromasia G4/800, OS 10.3.x, 1.25GB RAM, 2x80GB HD, 60GB firewire, Geforce4MX, Iiyama VMpro 455+413 Goldtouch keyboard, Cirque EasyCat trackpad, D-Link DSL-604+ |
|
|
|
|
|
#4 |
|
League Commissioner
Join Date: Jan 2002
Posts: 5,536
|
ah. okay then, background jobs 101, here we go...
you can "fork" a backgound job, and it becomes detached from your terminal command line... Code:
% disktool -m theDisk & # <- '&' fork process into the background you can manage background jobs with the 'jobs' command and switch among them with the %n command where n is the job number, but that is not interesting for our purposes here, except for testing. what is interesting is that the background process is a child of the parent terminal process, and when the parent dies, it should commit infanticide, that is, kill all children before dying. so, why sleep for 10 seconds? well, we want to give the background job some time to a) get started b) do it's dirty business c) go into the comatose state that we're trying to solve if this is a cron job, maybe even let them sleep for longer since we don't have observations of how long it will take to accomplish a, b and c, and we don't care, much, so long as the sleep is long enough. so, the idea is to dismount the disk in the background, snooze for a bit, then exit and the hung background job should die, too. it's a bit of a kiuge, but, if disktool gets fixed to behave appropriately, we don't need to change our script because it'll still work. it should be documented why we did it this way, though, for posterity. so, test a background job that is comatose, and kill the parent. when that satisfies, modify your cron script a la... Code:
disktool -m theDisk & # fork mount in the background sleep 30 # snooze 30 seconds exit # die, taking the coma mount job with me |
|
|
|
|
|
#5 |
|
Triple-A Player
Join Date: Jun 2002
Posts: 68
|
merv - 1000 thanks for those instructions. i have exactly the same
trouble as djn1. |
|
|
|
|
|
#6 |
|
MVP
Join Date: Apr 2002
Location: UK
Posts: 1,212
|
Hi Merv.
Ok here's what I did: I created a shell script with the lines: disktool -m disk2s9 & # fork mount in the background sleep 30 # snooze 30 seconds exit # die, taking the coma mount job with me which I then saved as /bin/mount_translocate.sh Next I ran: sudo chmod +x /bin/mount_translocate.sh rehash I then ran the script and used Process wizard to keep an eye on what was running. While it was running (i.e. before the 30 seconds was up) Process Wizard reported three processes: /bin/sh /bin/mount translocate.sh sleep 30 disktool -m disk2s9 At the end of the thirty seconds "/bin/sh /bin/mount translocate.sh" and "sleep 30" dissapear but "disktool -m disk2s9" is still there. If I repeat the process I get another occurrence of "disktool -m disk2s9" and so on. I'm not sure what this tells us other than the "hung background job" isn't dying as expected.
__________________
chromasia G4/800, OS 10.3.x, 1.25GB RAM, 2x80GB HD, 60GB firewire, Geforce4MX, Iiyama VMpro 455+413 Goldtouch keyboard, Cirque EasyCat trackpad, D-Link DSL-604+ |
|
|
|
|
|
#7 |
|
MVP
Join Date: Apr 2002
Location: UK
Posts: 1,212
|
Merv,
one final thing: "disktool -m disk2s9 &" doesn't return me to the command prompt but it does allow me to use a carriage return to get to it rather than having to use ctrl-c ... is this of any relevance?
__________________
chromasia G4/800, OS 10.3.x, 1.25GB RAM, 2x80GB HD, 60GB firewire, Geforce4MX, Iiyama VMpro 455+413 Goldtouch keyboard, Cirque EasyCat trackpad, D-Link DSL-604+ |
|
|
|
|
|
#8 |
|
MVP
Join Date: Jan 2002
Location: Boston, MA
Posts: 1,489
|
I just ran disktool -m to mount a firewire drive I was fiddling with and it returned me to the command line just fine...perhaps the problem got fixed between last year and now.
Code:
$ disktool -m disk3s9
disk3s9 device will attempt to be mounted ...
***Disk Appeared ('disk3s9',Mountpoint = '', fsType = 'hfs', volName = 'FireWire40')
Disk Mounting Completed
[02:05pm][russcam:/dev]
__________________
:: 3.4GHz Core i7 iMac 4GB RAM :: Black MacBook SR :: 10.7.2 :: iPhone 4 / iOS 5 :: |
|
|
|
![]() |
|
|