ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I need to end the script I am running from /dev/scd0, so I can umount the drive. During the script I call a 2nd one on the systems hard drive, and transfer to the /root, but I can not umount the cdrom drive. Gives error - device is busy.
Originally posted by yoderp Ok I am new to the Linux shell script.
What command do you use to end a bash script.sh?
I need to end the script I am running from /dev/scd0, so I can umount the drive. During the script I call a 2nd one on the systems hard drive, and transfer to the /root, but I can not umount the cdrom drive. Gives error - device is busy.
If somthing is running on a terminal, something like CTRL+C will kill it.
If this does not work try CTRL +Z and then
Code:
kill %%
But in most cases when you have a process using a mounted partition and you get a device busy
try
where PID is the process ID from a command like top or /sbin/pidof
You can't unmount a device from the VFS (virtual filesystem switch) properly while any file or directory handles are open within the part of the virtual filesystem that points to the device. You get a message saying “device busy”. What you can do here (assuming you have a non-ancient kernel) is a “lazy unmount”. Type
Out of curiosity, is fuser -k a user-accessible app? And if say root is running a script, does that count as accessing a file? I'm just curious to find out if a user could kill a script started by root by terminating the process reading the script...
Ok looks like I am getting a lot of feed back. Thanks.
Let me add some info here. I am using Mandrake v9.2. I am running this script from the Konsole cls as the root user. I have tried end, done, and exit 0 as commands to kill the 1st script. Below are the 2 scripts I am running. #1 is from /mnt/scd0 (on cd), then transfers to HDD script #2. At this point I am trying to unmount the /mnt/cdrom to change out the media, but not matter what I have tried the drive stays mounted.
---------------------------------------------------------------------------------------------------------
mount /dev/scd0 /mnt/cdrom
cd /mnt/cdrom
./test_setup.sh
----------------------------------------------------------------------------------------------------------
#!/bin/sh
echo "Running script test_setup.sh "
echo
echo
echo "Copying Linux xxxxxxxxxx files to hard drive from cd"
echo
cp Linuxxx_1.900.tar.gz /root
echo
echo "Copying new Linux xxxxxxxxxx defualt.ini test setup file to /root/Linuxxx_1.900 directory "
echo "Copying xxxxxxxxxx setup test scripts to /root "
cp default_new.ini /root/Linuxxx_1.900/default.ini
cp test_setup.sh /root/test_setup.sh
cp test_umount.sh /root/test_umount.sh
cp go.sh /root/go.sh
cp transferred_to_root.sh /root/transferred_to_root.sh
cd /root
./transferred_to_root.sh
exit 0
----------------------------------------------------------------------------------------------------------
2nd script file on HDD /root
----------------------------------------------------------------------------------------------------------
#!/bin/sh
ocho
echo "Running script transferred_to_root.sh "
echo
echo
echo "Unzipping Linux xxxxxxxxxx files to /root directory "
tar -zxvf Linuxxx_1.900.tar.gz
echo
echo "Install process has been transferred to your systems hard drive "
echo
echo
umount /dev/scd0
echo "The cdrom drive should now been umounted" (cls gives error - device is busy)
echo "Now remove the Linnux xxxxxxxxxx install media from the CD drive, and replace it "
echo "with the Linux xxxxxxxxxx Test Media CD v1.00 "
echo
echo "After you have inserted the xxxxxxxxxx Test Media v1.00 - type "./go.sh"
echo
echo
exit 0
----------------------------------------------------------------------------------------------------------------
The device is busy because the konsole's shell is using it, not the script.
A script can't change the working directory of the shell that it's called from, so you won't be able to unmount the device from the second script while the shell in your konsole session has /mnt/cdrom as the working directory.
It would be better to have the first script cd into /mnt/cdrom (perhaps passed as a command-line option to the script); that way, the script can be run from another directory. Alternatively, you should be able to do a umount -l to delay unmounting of the device until the konsole's shell has finished with it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.