LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Bash script help (https://www.linuxquestions.org/questions/linux-newbie-8/bash-script-help-453344/)

OnoTadaki 06-10-2006 12:20 AM

Bash script help
 
Hello!

I'm working on a simple bash script that ultimately will read the name of a cd/dvd and output that as a header into a document, then read the file contents and output them formatted into the file. My first problem is that I don't know how to get the disk name outputted without Volname (Read Next). My second problem is that I'm using Cygwin for Bash and unfortunately don't have Volname available.

So, I was thinking possibly outputting some LS with a switch that might show the volume name and just GREP'ing it out, but I've had no luck finding any way to get a volume name outputted without Volname.

Any help getting a disk's name outputted without Volname, or even a complete script of how someone else would do this if you had the time, would be great!

Thanks!

Tinkster 06-10-2006 02:29 AM

Well ... ls is iso9660 unaware. The volume name in iso9660 begins at
offset x8028, so a line like
Code:

~ ]$ dd if=/dev/scd0 bs=2048 skip=16 count=1 2>/dev/null|cut -b 41-54
KNOPPIX

should do the trick (don't ask me why I think that the volume is 13
bytes long at best :})... you can play with the values if it fails.


Cheers,
Tink

elluva 06-10-2006 02:42 AM

Works great, but if I were you I'd take /dev/cdrom, this way you use the link to the proper device and de device name itself can change.
Just a detail though.

Tinkster 06-10-2006 02:44 AM

Heh ... true enough (not that I'm suggesting that the link
is always correct in all installations ;}).

And another correction - the volume name can be 32 Bytes
long, not 13. I looked at mkisofs' man-page ;}
Code:

dd if=/dev/cdrom bs=2048 skip=16 count=1 2>/dev/null|cut -b 41-73


Cheers,
Tink

OnoTadaki 06-10-2006 02:46 PM

Thank you all for the help!

Tinkster 06-10-2006 03:13 PM

Welcome :}

... so is this version more workable for you than volname?



Cheers,
Tink

OnoTadaki 06-10-2006 03:17 PM

Unfortunately, Cygwin has no /Dev, so this method doesn't work with it, but I did try that out and the idea works well in an actual fully functional Bash environment. I don't know if there is any way to get a volume name through this barring switching completely over to Linux on that computer or somehow importing the Volname command over to it.

Tinkster 06-10-2006 03:32 PM

I'd obviously be in favour of moving to Linux ;}

However, if you prefer to e operating in WinDOHs at this stage
you could give qemu a shot, and emulate a PC running a real Linux
under Windows. Or, of course, go the other way round and install
some Linux, run qemu and have winDOHs tucked away in a virtual
machine :}

As for cygwin itself; I wouldn't have a clue whether it has the
executable ready for install, or how trivial it would be to try
and port that piece of software.


Cheers,
Tink

unSpawn 06-10-2006 07:59 PM

Unfortunately, Cygwin has no /dev
Quote:

"Beginning with Cygwin 1.3.4, raw devices are accessible by Cygwin processes using fixed POSIX device names. These fixed POSIX device names are generated using a direct conversion from the POSIX namespace to the internal NT namespace. E.g. the first harddisk is the NT internal device \device\harddisk0\partition0 or the first partition on the third harddisk is \device\harddisk2\partition1. The first floppy in the system is \device\floppy0, the first CD-ROM is \device\cdrom0 and the first tape drive is \device\tape0"
So that would be \device\cdrom0 IIGC...

Of course I'd like to emphasise I'd rather see you use the versatile, robust, performant and generally way more efficient GNU/Linux over using the eternally blue-screeing, cut-n-perish, POS (Pitiful Operating System aka the MICROS~1 Game Platform)

jschiwal 06-10-2006 08:13 PM

I do the same thing at work. I installed Cygwin on our video encoder, and have a simple two or three line script that reads the DVD backup's directory and produces a PDF catalog of the videos I've backed up. ( Although each line has a lot of pipes, using sed and enscript, so the line count of the script isn't totally an honest measure.)

I don't read the volume name, but instead enter the name of the disk as an argument to the script. Since I occasionally don't get the disc label right anyway, what I label on the top of the DVD with a marker is what I use as an argument to the script, and is what the catalog shows.


All times are GMT -5. The time now is 07:18 AM.