LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 03-23-2010, 01:30 PM   #1
anurupr
Member
 
Registered: Mar 2010
Posts: 71

Rep: Reputation: 16
i need to get path to cdrom using /etc/mtab


i tried using grep command to do this
Code:
cat /etc/mtab | grep "/dev/sr0" | cut -f 2- -d' '|colrm 22
this basically gives the output "/media/CDNAME"
and i was able to get the output but the problem is that i need to get this path i.e. /media/CDNAME for CDNAME .obviously "CDNAME" will vary from cd to cd. so is it possible??
thanx in advance
 
Old 03-23-2010, 05:12 PM   #2
MS3FGX
LQ Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 361Reputation: 361Reputation: 361Reputation: 361
If I am understanding the question correctly, you just need to reverse what you are doing there. grep for the name of the CD rather than the device node, and process the output accordingly.
 
Old 03-23-2010, 07:32 PM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,999

Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
I could be getting this wrong, but if you know that all your cd / dvd titles will be in /media directory,
can't you just do 'ls /media/CDNAME'
 
Old 03-24-2010, 03:05 AM   #4
anurupr
Member
 
Registered: Mar 2010
Posts: 71

Original Poster
Rep: Reputation: 16
thnx for replying

yes that would work but it would work only if you knew the exact name . for example one of my dvds is shown as Digit Dvd 2005 in the Nautilus window but in the media folder its shown as Digit_DVD_2005, therefore it will change from cd to cd .. all i need to get is the part after /media/ and before iso "something" from mtab.. is that possible?
thnx in advance
 
Old 03-24-2010, 03:11 AM   #5
anurupr
Member
 
Registered: Mar 2010
Posts: 71

Original Poster
Rep: Reputation: 16
this is the output of my /etc/mtab

hope this might give a better idea of what i am asking
cat /etc/mtab

/dev/loop0 / ext4 rw,errors=remount-ro 0 0
proc /proc proc rw 0 0
none /sys sysfs rw,noexec,nosuid,nodev 0 0
none /sys/fs/fuse/connections fusectl rw 0 0
none /sys/kernel/debug debugfs rw 0 0
none /sys/kernel/security securityfs rw 0 0
udev /dev tmpfs rw,mode=0755 0 0
none /dev/pts devpts rw,noexec,nosuid,gid=5,mode=0620 0 0
none /dev/shm tmpfs rw,nosuid,nodev 0 0
none /var/run tmpfs rw,nosuid,mode=0755 0 0
none /var/lock tmpfs rw,noexec,nosuid,nodev 0 0
none /lib/init/rw tmpfs rw,nosuid,mode=0755 0 0
/dev/sda3 /host fuseblk rw 0 0
binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,noexec,nosuid,nodev 0 0
gvfs-fuse-daemon /home/bibingeorge/.gvfs fuse.gvfs-fuse-daemon rw,nosuid,nodev,user=bibingeorge 0 0
/dev/sr0 /media/Digit_Feb_2005 iso9660 ro,nosuid,nodev,uhelper=devkit,uid=1000,gid=1000,iocharset=utf8,mode=0400,dmode=0500 0 0
 
Old 03-24-2010, 03:36 AM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
awk '$1 ~ /sr0/ {print gensub( /\/media\//, "", "1", $2)}' /etc/mtab

Last edited by Tinkster; 03-24-2010 at 03:44 AM. Reason: Ooops ... forgot to strip the media part
 
Old 03-24-2010, 03:40 AM   #7
kainosnous
Member
 
Registered: Mar 2010
Location: Tennessee, USA
Distribution: Arch, Fedora
Posts: 59

Rep: Reputation: 18
If what you want is the name of the directory after /media/ you could send that line to sed like this:

Code:
CDNAME=$(cat /etc/mtab | grep /dev/sr0 | sed -e "s@^/dev/sr0 /media/\([^ ]*\).*@\1@")
echo $CDNAME
That would give you something like:

Code:
Digit_Feb_2005

Last edited by kainosnous; 03-24-2010 at 03:47 AM. Reason: Edited code to be a little cleaner
 
Old 03-24-2010, 05:52 AM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,999

Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
You can get rid of the cat and grep parts if you like:

Code:
CDNAME=$(sed -n '/sr0/s/.*media\/\([^ ]*\).*/\1/p' /etc/mtab)
 
  


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
cannot mount internal hard drive: .hal-mtab and .hal-mtab-lock messed up extremewaffles Linux - Newbie 3 07-01-2009 05:15 PM
/etc/mtab sulekha Linux - General 2 10-14-2008 08:13 PM
/media/.hal-mtab and /media/.hal-mtab-lock SlowCoder Linux - General 2 05-13-2008 04:17 PM
HP-UX ioscan CDROM device path gctaylor1 Other *NIX 3 11-08-2007 09:11 AM
/etc/mtab problem = can't mount anything--cdrom,floppy,etc. theo444 Slackware 11 08-23-2005 01:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:22 AM.

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
Open Source Consulting | Domain Registration