LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-19-2008, 03:10 PM   #1
perlabsrat
LQ Newbie
 
Registered: Jan 2008
Posts: 13

Rep: Reputation: 0
Variable that points to current cdrom on multiple systems


I want to write a shell script to copy files from my cdrom to say my /myfiles

This script will need to run on different distros RHEL,SLES, etc. and on various machines with very different configurations.


My question is this. How can the script determine where the cdrom is and its mount point?

EG:

If on system #1 the cdrom is /dev/hda - say mounted at /media/mycdrom

and

system #2 it happens to be at /dev/hdb and mounted at /mnt/cdrom


How would the script know where the cdrom is located on a given system if the location can change from system to system?


Is there a global system variable for something like this?

I found this thread but it assumes the drive is /dev/hdb
http://www.linuxquestions.org/questi...7/#post2065008

Last edited by perlabsrat; 06-19-2008 at 03:11 PM.
 
Old 06-19-2008, 03:51 PM   #2
Samotnik
Member
 
Registered: Jun 2006
Location: Belarus
Distribution: Debian GNU/Linux testing/unstable
Posts: 471

Rep: Reputation: 40
There is no way in linux to automatically determine what device or mount point belonged to cdrom.
 
Old 06-19-2008, 04:09 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
On most systems /dev/cdrom is a link to a real block device. Once you have discovered which device corresponds to /dev/cdrom you can easily use the mount command to discover the mount point, if any.
 
Old 06-20-2008, 11:12 AM   #4
perlabsrat
LQ Newbie
 
Registered: Jan 2008
Posts: 13

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Samotnik View Post
There is no way in linux to automatically determine what device or mount point belonged to cdrom.
Hmmm ok, well...
Is there a way for a script to know where it is being run from?

If the script were run from the cd is there some type of system variable that shows the execution path of the current script?
 
Old 06-20-2008, 05:55 PM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by perlabsrat View Post
Is there a way for a script to know where it is being run from?
To get the full path of the running script:
Code:
dir=$(cd $(dirname $0) && pwd)
the cd command does not change the current working directory of the script, since it runs in a subshell.
 
  


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
Set up Windows network with multiple access points newuser455 General 8 02-02-2005 06:12 PM
Multiple mount points alsm Linux - Software 1 03-28-2004 04:05 PM
Partitioning: File systems and Mount points Ice Dragon Linux - Newbie 3 03-11-2004 04:00 PM
multiple mount points for cds lavoisier Mandriva 2 10-22-2003 07:59 AM
Multiple Mount Points LinuxGeek Linux - General 2 07-28-2002 07:46 PM


All times are GMT -5. The time now is 10:37 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration