LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-16-2005, 11:37 AM   #1
yoderp
LQ Newbie
 
Registered: Jun 2005
Posts: 6

Rep: Reputation: 0
shell script question


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.
 
Old 06-16-2005, 11:52 AM   #2
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 52
Re: shell script question

Quote:
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
Code:
lsof  /dev/<device>
to identify the process and then kill it.
 
Old 06-16-2005, 11:56 AM   #3
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,990

Rep: Reputation: 67
You can exit a BASH script using “exit”.

You can also kill a running process using
Code:
kill PID
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
Code:
man umount
into a terminal for more information.
 
Old 06-16-2005, 01:18 PM   #4
nixcraft
Member
 
Registered: Nov 2004
Location: BIOS
Distribution: RHEL3.0, FreeBSD 5.x, Debian 3.x, Soaris x86 v10
Posts: 379

Rep: Reputation: 30
You need to use command:
Code:
fuser -km  /dev/scd0
This command will kill it no matter what user is doing on scd0
 
Old 06-16-2005, 02:10 PM   #5
rose_bud4201
Member
 
Registered: Aug 2002
Location: St Louis, MO
Distribution: Xubuntu, RHEL, Solaris 10
Posts: 927

Rep: Reputation: 30
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...
 
Old 06-16-2005, 03:11 PM   #6
yoderp
LQ Newbie
 
Registered: Jun 2005
Posts: 6

Original Poster
Rep: Reputation: 0
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
----------------------------------------------------------------------------------------------------------------
 
Old 06-16-2005, 04:47 PM   #7
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,990

Rep: Reputation: 67
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Script Question abdul_zu Programming 7 10-06-2005 03:33 AM
shell script Question Whiteghost Programming 4 09-25-2005 10:05 PM
Shell Script Question. rvijay Linux - General 2 07-14-2005 06:41 PM
Shell script question... defa0009 Linux - General 7 04-26-2005 08:16 PM
shell script question rrwhite Linux - General 3 09-15-2004 01:01 AM


All times are GMT -5. The time now is 05:27 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration