Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Unmount from bash script with user in mounted directory?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
Rhone
n00b
n00b


Joined: 14 Jun 2003
Posts: 6

PostPosted: Wed Jul 02, 2003 5:55 pm    Post subject: Unmount from bash script with user in mounted directory? Reply with quote

I'm working on a bash script for creating ISOs for the downloadable Neverwinter Nights resources and Linux client, including an installation script for the first CD.

I haven't done anything this complex with bash before, though, and I'm running into a little dilemma: Ideally the user would mount the first CD, change to the directory, and run ./setup.sh or whatever. I would like the script to be able to install everything from the first CD, then unmount it and prompt the user to switch to the second CD, then mount that and continue installation. However, I know that umount doesn't like unmounting something if a user is in the mounted directory.

So, how can my script unmount the CD even though a user is in the CD's directory when the script is run? Any help would be appreciated. :)
Back to top
View user's profile Send private message
Petyr
Guru
Guru


Joined: 08 Jan 2003
Posts: 471
Location: San Diego, CA, USA

PostPosted: Wed Jul 02, 2003 6:47 pm    Post subject: Reply with quote

Why not have the script copy a script to the user's home dir, then fork off a process to go and run that script and kill itself.
The forked process then can do the rest of the install then back out from the cddrive, unmount, prompt etc etc etc

Petyr
Back to top
View user's profile Send private message
Rhone
n00b
n00b


Joined: 14 Jun 2003
Posts: 6

PostPosted: Wed Jul 02, 2003 8:14 pm    Post subject: Reply with quote

Thanks for the response, Petyr. That leaves me with two questions/problems, though....

1) How do I fork a process in bash? Man fork doesn't help, as that seems to be describing a C function. I've done some googling and haven't found anything really helpful.

2) If I do manage to accomplish what you describe, then I no longer have a script running from the CD (good), but there is still a user sitting in the mounted directory. Sure, I can change directories from within the scripts, but that is separate process from the user process that is still sitting in the directory where the user originally ran the script. How do I force the user out?
Back to top
View user's profile Send private message
Petyr
Guru
Guru


Joined: 08 Jan 2003
Posts: 471
Location: San Diego, CA, USA

PostPosted: Thu Jul 03, 2003 7:09 am    Post subject: Reply with quote

Rhone wrote:
1) How do I fork a process in bash? Man fork doesn't help, as that seems to be describing a C function. I've done some googling and haven't found anything really helpful.

I think what you could do is just in the script issue a command to run in the background, that way the script keeps on going immediatly (potentially ending ^^) while the command issued goes off in a seperate process
i.e.
Code:
(random stuff)
cp myfile ~${USER}/forkme
chmod 700 ~${USER}/forkme
~${USER}/forkme &

it's the & that's the important part. From there you could probably put a sleep 1 in the forkme script and that should make very sure that the parent script has terminated.
Rhone wrote:
2) If I do manage to accomplish what you describe, then I no longer have a script running from the CD (good), but there is still a user sitting in the mounted directory. Sure, I can change directories from within the scripts, but that is separate process from the user process that is still sitting in the directory where the user originally ran the script. How do I force the user out?

Dunno how to answer that one... Maybe in the readme you can tell the user to not be in the dir to run the script :?
Yea I know... who really reads the README :wink:

Petyr
Back to top
View user's profile Send private message
JuddRogers
n00b
n00b


Joined: 23 Jun 2003
Posts: 32
Location: Austin, Texas

PostPosted: Sun Jul 06, 2003 4:39 pm    Post subject: Catch the unmount error? Reply with quote

If your bash script checks for unmount failing (returning non-zero as I recall), then you can echo a message telling the user to please go back to the original shell and cd to home and then press enter.

You can use something like:
Code:

while read junk; do
sleep 1
done

to wait until the user presses enter.

But you will need a new window to display the message. You might want to start an xterm or something to run the real script in.

You might want to do this in python :lol:
Judd
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum