Copy contents of whatever's loaded into the CD drive


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy contents of whatever's loaded into the CD drive
# 1  
Old 11-08-2011
Copy contents of whatever's loaded into the CD drive

Hello everyone,

I have about 1500 compact discs of seismic data that I need to retrieve and place onto the hard drive so that I can index and process them.
The data was generated at 20 seismic stations and each disc has a been assigned unique name. The name is NOT necessarily what is on the disc itself. In fact, there is no conformity into what the station operator chose to call each disc when it was created. Some of the disc names contain Cyrillic (Russian) characters and white space. The new name format is a nine character system that contains the four letter station code, the two digit year, a letter N, and a two digit code representing disc sequence.

I would first like to create a KSH script that does these things:

Once mounted in the CD drive bay, identify the disc name and store within a variable. (This is what I have not figured out how to do.)

Poll the user for the station name.
Poll the user for the new disc name.

Copy the contents of the CD into the appropriate directory.
Change the permissions on the file.
Rename the newly copied folder with the contents to reflect the newly assigned disc name.

I've got this much, which is a very wordy script that doesn't quite work. I want to remove the requirement for the user to type in the disc mount ID, and instead use what is there. There's got to be a variable somewhere in the system, but hell if I can't find it.

Anyone got any suggestions? I'm combing through the manuals, doing google searches, searching this forum, but haven't yet found the answer. Scripting, if you haven't guessed it, is essentially new to me. My programming skills have been proven to be rusty enough to get red dust on the keyboard. The last time I did anything remotely like this was in 1985 on a DEC PDP11.

---
Dan's KSH script example:

Code:
USEAGE="usage: copyCD - Copies the seismic CDs into the collection"    #
print -n "Ensure that the CD is first loaded within the CD drive and is mounted."
print -n "Enter the CD name: (SSSSYYNDD) where SSSS = station name, YY = year, DD = Disc ID:  "
read diskid
print -n "Enter the loaded CD identification: \n"           # I want to automate this part!
read cdname
print -n "Your disc name is "$diskid"\n"
print -n "Enter the name of the Station. "
read stationid
if [[ ! -d ~/Documents/Sample_data/$stationid ]]
then 
    mkdir ~/Documents/Sample_data/$stationid
    print -n "~/Documents/Sample_data/"$stationid" created.\n"
else
    print -n "Station directory already exists.\n"
fi

print -n "Begin copy of contents of "$cdname" into directory ~/Documents
/Sample_data/"$stationid"/"$diskid"/\n"

cp -rn "/media/$cdname" "~/Documents/Sample_data/$stationid/"

chmod -R 775 "~/Documents/Sample_data/$stationid/$cdname"

mv ~/Documents/Sample_data/$stationid/$cdname ~/Documents/Sample_data/$stationid/$diskid


Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.

Last edited by Franklin52; 11-09-2011 at 03:38 AM.. Reason: Please use code tags, thank you
# 2  
Old 11-08-2011
What's your system?

Are you allowed to install programs?

I can get the disk name from isoinfo on my linux system, part of cdrtools, but it needs to read direct from the cd device:

Code:
$ isoinfo -d -i /dev/cdrom2 
CD-ROM is in ISO 9660 format
System id:
Volume id: GRMCPRXFRER_EN_DVD
Volume set id: GRMCPRXFRER_EN_DVD
Publisher id: MICROSOFT CORPORATION
Data preparer id: MICROSOFT CORPORATION, ONE MICROSOFT WAY, REDMOND WA 98052, (425) 882-8080
Application id: CDIMAGE 2.54 (01/01/2005 TM)
Copyright File id:
Abstract File id:
Bibliographic File id:
Volume set size is: 1
Volume set sequence number is: 1
Logical block size is: 2048
Volume size is: 1574554
El Torito VD version 1 found, boot catalog is in sector 22
NO Joliet present

NO Rock Ridge present
Eltorito validation header:
    Hid 1
    Arch 0 (x86)
    ID 'Microsoft Corporation'
    Cksum 4C 49 OK
    Key 55 AA
    Eltorito defaultboot header:
        Bootid 88 (bootable)
        Boot media 0 (No Emulation Boot)
        Load segment 0
        Sys type 0
        Nsect 8
        Bootoff 2DE 734
$

Unless they specifically labelled and IDed all these disks though I suspect you're going to be disappointed. Most people don't bother and leave them as some generic name.

You're more likely to find what you want in looking at the contents of these CD's, the identification may be present somewhere in the data.
# 3  
Old 11-08-2011
I am using OpenSUSE, latest version.
If I can do this without knowing the CD name, all the better. I just haven't figured it out yet. Somehow I need to seek the disk and find out the folder name without explicitly asking the user to "look" at the directory.

In addition, I have this sample script ALMOST running, but it blows up on the "mv" command, with an error that has me baffled. Also, since the station name is already part of the CD name, I might be able to parse that out and not force the user to enter it twice.

Help is appreciated.


--
Code:
msugws@dynamic-mackeyke-msu:~> ksh copyCD
Ensure that the CD is first loaded within the CD drive and is mounted.
Enter the CD name: (SSSSYYNDD) where SSSS = station name, YY = year, DD = Disc ID:  NMA207N08
Enter the loaded CD identification: 
Мой диск
Your disc name is NMA207N08
Enter the name of the Station. NMA2
Station directory already exists.
Begin copy of contents of Мой диск into directory ~/Documents/Sample_data/NMA2/NMA207N08/
mv: target `/home/msugws/Documents/Sample_data/NMA2/NMA207N08' is not a directory
msugws@dynamic-mackeyke-msu:~>

----
Ksh script:

Code:
USEAGE="usage: copyCD - Copies seismic CDs for the NERSP program"    #
print -n "Ensure that the CD is first loaded within the CD drive and is mounted.\n"
print -n "Enter the CD name: (SSSSYYNDD) where SSSS = station name, YY = year, DD = Disc ID:  "
read diskid
print -n "Enter the loaded CD identification: \n"
read cdname
print -n "Your disc name is "$diskid"\n"
print -n "Enter the name of the Station. "
read stationid
if [[ ! -d ~/Documents/Sample_data/$stationid ]]
then 
    mkdir ~/Documents/Sample_data/$stationid
    print -n "~/Documents/Sample_data/"$stationid" created.\n"
else
    print -n "Station directory already exists.\n"
fi
print -n "Begin copy of contents of "$cdname" into directory ~/Documents/Sample_data/"$stationid"/"$diskid"/\n"
cp -rn "/media/$cdname" "/home/msugws/Documents/Sample_data/$stationid/"
chmod -R 775 "/home/msugws/Documents/Sample_data/$stationid/$cdname"
mv /home/msugws/Documents/Sample_data/$stationid/$cdname /home/msugws/Documents/Sample_data/$stationid/$diskid

--

Last edited by pludi; 11-09-2011 at 04:29 AM..
# 4  
Old 11-08-2011
Well, look at /home/msugws/Documents/Sample_data/NMA2/NMA207N08. Is it a directory? If not, you can't copy things into it...

OpenSUSE should be able to install isoinfo one way or another, though I don't know what package name it hides inside for that distribution.

Quote:
Originally Posted by ws6transam
I am using OpenSUSE, latest version.
If I can do this without knowing the CD name, all the better. I just haven't figured it out yet. Somehow I need to seek the disk and find out the folder name without explicitly asking the user to "look" at the directory.
You don't have to ask the user to do something, just do it.

How to extract the data from your CD depends entirely on what the data in the CD looks like, though. I don't know for sure it's in there.
# 5  
Old 11-08-2011
Maybe what I need is to rename the directory, not necessarily move it. However I thought mv was also the utlility for renaming stuff; i.e. files, and folders. I've used mv successfully at the command line to rename folders but when adding the $variables and doing it int eh shell script, it fails.

Ahh--- the $64,000 question. If you don't know what's on the CD, how do you copy it? That's what I need to find out. MY CD's are of varying formats: Sometimes there will be a top folder that is jammed with 4,000 little data files. Sometimes there is a subfolder called "Data" which contains the data files, along with a couple of extra supplemental folders with some small executable companions that I don't really care about. Other times, the discs will contain a single folder with the subfolders underneath it. SInce the format varies, I thought I could just identify the CD, specify the copy, and stream the whole thing into a single folder, then spend a few minutes deleting the extra folders if I find any, as I am inspecting the discs. The time consuming part is all the typing and copying and pasting necessary for getting the data onto the system. I just haven't figured out how to identify a mounted CD, other than to manually inspect with an ls command of /media. Unfortunately the CD isn't the only thing in that directory, and the CD name changes every time you mount a disc. It's a moving target.

---------- Post updated at 08:32 PM ---------- Previous update was at 04:43 PM ----------

I'm still at this ~
The problem I'm having is that whenever I load a CD into the drive, it mounts in the media directory with a completely new name, making it rather hard to pin down when running a script.

So, tonight I entered superuser, and created a directory called /media/cdrom as follows:

Code:
linux-snq2:/media # ls
BIG STICK 2  MRR2011
linux-snq2:/media # mkdir cdrom
linux-snq2:/media # ls
BIG STICK 2  cdrom  MRR2011

MRR2011 is the already-mounted CD with some miscellaneous documents.

Next, I issued a mount command as follows:

Code:
linux-snq2:/media # mount /dev/cdrom /media/cdrom
mount: block device /dev/sr0 is write-protected, mounting read-only
linux-snq2:/media #

I then left superuser, and checked up on things:

Code:
daniel@linux-snq2:/media> ls
BIG STICK 2  cdrom  MRR2011
daniel@linux-snq2:/media> cd cdrom
daniel@linux-snq2:/media/cdrom> ls
ACKNOWL.HTM   AUTORUN.INI  IMAGES        PAPERS       PAPERS4.HTM  PREVIOUS.HTM  ROADMAP3.HTM
ACRONYMS.HTM  COVER.HTM    INDEX.HTM     PAPERS1.HTM  PAPERS5.HTM  README.TXT    ROADMAP4.HTM
AUTORUN.EXE   GUIDE.HTM    MRR2011.ICO   PAPERS2.HTM  PAPERS6.HTM  ROADMAP1.HTM  ROADMAP.HTM
AUTORUN.INF   HARDCOPY     MRRSTYLE.CSS  PAPERS3.HTM  PAPERS.HTM   ROADMAP2.HTM  TOC.HTM
daniel@linux-snq2:/media/cdrom> cd /media/MRR2011
daniel@linux-snq2:/media/MRR2011> ls
ACKNOWL.HTM   AUTORUN.INI  IMAGES        PAPERS       PAPERS4.HTM  PREVIOUS.HTM  ROADMAP3.HTM
ACRONYMS.HTM  COVER.HTM    INDEX.HTM     PAPERS1.HTM  PAPERS5.HTM  README.TXT    ROADMAP4.HTM
AUTORUN.EXE   GUIDE.HTM    MRR2011.ICO   PAPERS2.HTM  PAPERS6.HTM  ROADMAP1.HTM  ROADMAP.HTM
AUTORUN.INF   HARDCOPY     MRRSTYLE.CSS  PAPERS3.HTM  PAPERS.HTM   ROADMAP2.HTM  TOC.HTM
daniel@linux-snq2:/media/MRR2011>

Note that both /media/MRR2011 and /media/cdrom now reflect the same contents.

---
Though this *might* work, what I need to figure out is how to automount EVERY cdrom EVERY time, automatically so that I don't have to enter superuser and explicitly mount the disc each time. If I can get the disc to locate to the same location, I can write my script..

Of course, you are probably thinking that there's got to be a simpler, more elegant solution.... and so do I! So I'm still open to suggestions.

---------- Post updated at 09:06 PM ---------- Previous update was at 08:32 PM ----------

Okay --- Last bit of script for tonight. I found out that the double quotes were the problem in my ksh.

Now, whenever I mount the disc as superuser and manually mount it as /media/cdrom, the script will copy the files appropriately into a renamed folder at it's destination.

Now I just need to figure out how to get the disc to mount automatically each time, and I'll be nearly ready to cram these 1500 discs onto the system for phase 2 of the project.

---
Code:
USEAGE="usage: copyCD - Copies seismic CDs for the NERSP program" #
print -n "Ensure that the CD is first loaded within the CD drive and is mounted.\n"
print -n "Enter the CD name: (SSSSYYNDD) where SSSS = station name, YY = year, DD = Disc ID: "
read diskid
# print -n "Enter the loaded CD identification: \n"
# read cdname
print -n "Your disc name is "$diskid"\n"
print -n "Enter the name of the Station. "
read stationid

if [[ ! -d ~/Documents/ ]]
then
mkdir ~/Documents/
print -n "~/Documents/" created.\n"
fi

if [[ ! -d ~/Documents/Sample_data ]]
then
mkdir ~/Documents/Sample_data/
print -n "~/Documents/Sample_data/" created.\n"
fi

if [[ ! -d ~/Documents/Sample_data/$stationid ]]
then
mkdir -p ~/Documents/Sample_data/$stationid
print -n "~/Documents/Sample_data/"$stationid" created.\n"
else
print -n "Station directory already exists.\n"
fi

print -n "Begin copy of contents of /media/cdrom into directory ~/Documents/Sample_data/"$stationid"/"$diskid"/\n"

mkdir ~/Documents/Sample_data/$stationid/cdrom

cp -Tr --preserve=timestamps /media/cdrom/ ~/Documents/Sample_data/$stationid/cdrom/

chmod -R 775 ~/Documents/Sample_data/$stationid

mv ~/Documents/Sample_data/$stationid/cdrom/ ~/Documents/Sample_data/$stationid/$diskid

---------- Post updated at 10:14 PM ---------- Previous update was at 09:06 PM ----------

Last bit for tonight - I've been going on this for fourteen hours now.

I've had partial success with getting the mount to work, but I need to "touch" the CDROM with Dolphin before the automount process works.

However, by adding the following line to my /etc/fstab file, the cdrom loads as /media/cdrom . It doesn't work unless I poke the CDROM with Dolphin first, so it might not be the appropriate solution. However I'm at my wit's end on this one.

My contents of /etc/fstab where I simply added line 3.
--
Code:
/dev/disk/by-id/ata-WDC_WD1200JB-00CRA1_WD-WMA8C3860827-part1 /                    ext4       acl,user_xattr        1 1
/dev/disk/by-id/ata-WDC_WD400BB-00FJA0_WD-WCAJC1722258-part5 swap                 swap       defaults              0 0
/dev/cdrom           /media/cdrom         auto       user,noauto,exec,ro   0 0
proc                 /proc                proc       defaults              0 0
sysfs                /sys                 sysfs      noauto                0 0
debugfs              /sys/kernel/debug    debugfs    noauto                0 0
usbfs                /proc/bus/usb        usbfs      noauto                0 0
devpts               /dev/pts             devpts     mode=0620,gid=5       0 0

--

Last edited by pludi; 11-09-2011 at 04:30 AM..
# 6  
Old 11-09-2011
Quote:
Originally Posted by ws6transam
Ahh--- the $64,000 question. If you don't know what's on the CD, how do you copy it? That's what I need to find out. MY CD's are of varying formats: Sometimes there will be a top folder that is jammed with 4,000 little data files. Sometimes there is a subfolder called "Data" which contains the data files, along with a couple of extra supplemental folders with some small executable companions that I don't really care about. Other times, the discs will contain a single folder with the subfolders underneath it. SInce the format varies, I thought I could just identify the CD, specify the copy, and stream the whole thing into a single folder, then spend a few minutes deleting the extra folders if I find any, as I am inspecting the discs. The time consuming part is all the typing and copying and pasting necessary for getting the data onto the system. I just haven't figured out how to identify a mounted CD, other than to manually inspect with an ls command of /media. Unfortunately the CD isn't the only thing in that directory, and the CD name changes every time you mount a disc. It's a moving target.
If the disks aren't consistent, then you can't depend on getting the name from the disk in any form. You might kludge something that'd work for a few but you'd still need to *check* every one of them, kind of defeating the point.

How about getting a big list of stations instead, and popping in the disks the program asks for?
Quote:
Though this *might* work, what I need to figure out is how to automount EVERY cdrom EVERY time, automatically so that I don't have to enter superuser and explicitly mount the disc each time. If I can get the disc to locate to the same location, I can write my script..
You had the right idea with the 'user' option in /etc/fstab. There's no reason it shouldn't work. what exactly does it not do, and what does poking it in dophin do?
# 7  
Old 11-09-2011
Thanks, I think I finally got it!

What I've added to the script is the command:

Code:
mount /dev/cdrom

I placed it inside the script after the first user prompt to give the drive time to spin up before the copy command is issued. This must be what was happening when I 'touched' the cdrom with Dolphin. It was mounting the drive. Now it's mounting without drama and going to town with the copy. I might add an explicit umount command at the very end of the script to tidy things up and ready it for the next CD.
Code:
umount /dev/cdrom



Now, the contents are mounted at a consistent location, every time! In addition, the contents of the CDROM are written to the appropriate directory name with the assigned CD identification for easy retrieval.

...now, can I embed this script into it's own little icon on my window? Something that launches a terminal window, retrieves the CD number from the operator, then closes when finished? That'd be even 20% cooler. I'll work on that next, then get busy putting some discs into the system.

Phase 2 is to create a script that seeks each directory, identifies the data format, retrieves start & stop times from each file segment, then creates a database.

After that, (phase 3) it starts to get tricky as I begin to audit the timing, concantenate the files into larger, more manageable sizes, and then begin converting them from their various formats into a standard format.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to copy contents

I am trying to move content of a folder usingls /backup/db_backups/INCREMENTAL/|while read file ; do mv $file /backup_LOCAL/db_backups/INCREMENTAL/ done...but when I run this command using a bash script I'm getting this error ./test.sh mv: cannot stat... (6 Replies)
Discussion started by: rocking77
6 Replies

2. Shell Programming and Scripting

Copy contents of one file to another

I need to write a script (in bash) that copies the content of the first file in each folder of a directory to the second file in the same folder. I tried this and it didn't work - it just came back with errors and I'm not sure how to fix it. Help is very much appreciated! for mpdir in... (4 Replies)
Discussion started by: LeftoverStew
4 Replies

3. Shell Programming and Scripting

Need help to copy contents of a file

Hi, I am stuck up with a problem of copying the contents of a directory where one of the folder name is changed daily. Problem: I have the folder structure as: RefWorlds2/LINGCC4_X64/odsdev/odessy/UTI/621GA_build_xxx/.../.. In the above path the build number (xxx) will be changed... (3 Replies)
Discussion started by: SathaKarni
3 Replies

4. UNIX for Dummies Questions & Answers

Real time status of tape drive loaded for backup

Do we have a way in solaris to actuallyu check in real time the activity of a tape when it is loaded for backup? I know mt -f /dev/rmt/0n stat will provide the status. If it's busy, meaning it's currrently on backup mode or someone is using it (fuser -u /dev/rmt/0n) I wanted to check if the... (3 Replies)
Discussion started by: lhareigh890
3 Replies

5. Shell Programming and Scripting

copy the contents between two keywords to a new file.

Hi All, I want to edit my gate level netlists by searching for the content between two patterns eg: ff1 \test/a0 ( .CLK(\test/ClkInt0_acb_00x1 ),.D(\test/Rakicc ), .QB(\test/X ), .VDD(1'b1), .VSS(1'b0)); ff1 \test/a1 ( .CLK(\test/medis0_acb_00x1 ),.D(\test/hedwc ), .QB(\test/X ),... (6 Replies)
Discussion started by: naveen@
6 Replies

6. Windows & DOS: Issues & Discussions

List Contents of Drive by size

I am having difficulty listing the contents of a specific disk drive including hidden files and folders by size on disk. Its been a while since i have used dos and batch files in windows as am used to UNIX so was wondering if anybody could help me with this? Regards, Alan Jackson (1 Reply)
Discussion started by: pure_jax
1 Replies

7. Shell Programming and Scripting

copy contents of one column in another

Hi, I want to pick contents of a column in a file and copy the contents of this to other column. awk can be used for this, but the number of fields are higher so awk will not help. Any other way to do this. e.g following file has some contents a follows a,b,c,d,e,f,9,0 i need... (4 Replies)
Discussion started by: raman1605
4 Replies

8. UNIX for Dummies Questions & Answers

copy folder contents

I need to make a new dir in side the dir lab5 the new dir is called testLab5 without changing directories copy all files from your lab5 directory into your testLab5 directory then i have to without chaning directories and using exactly one command remove all files that start with the... (1 Reply)
Discussion started by: robsk8_99
1 Replies

9. UNIX for Dummies Questions & Answers

How to a see the contents of my CD drive

How to a see the contents of my CD drive in a Scoopen server station. In a windows based system you just go to mycomputer- and than double click the cd rom drive icon...simple....But i need to see the same but for a SCO open server....i want the same for a floppy drive tooo... By the way, i... (4 Replies)
Discussion started by: BAM
4 Replies

10. UNIX Desktop Questions & Answers

How to a see the contents of my CD drive

in a Scoopen server station. In a windows based system you just go to mycomputer- and than double click the cd rom drive icon...simple....But i need to see the same but for a SCO open server....i want the same for a floppy drive tooo... By the way, i tried (scoadmin ) command but couldnt go... (1 Reply)
Discussion started by: BAM
1 Replies
Login or Register to Ask a Question