LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Best way to automatically copy files off of a cd to a specific folder? (https://www.linuxquestions.org/questions/linux-software-2/best-way-to-automatically-copy-files-off-of-a-cd-to-a-specific-folder-888186/)

valunthar 06-24-2011 03:23 PM

Best way to automatically copy files off of a cd to a specific folder?
 
What would be the best way to automatically copy all of the data off of a library of cds to a specific folder on the computer? I was thinking of running a bash script but I've run into a few snags figuring out the correct way to do it. Mainly due to the fact that the cd drive is mounted in a different folder in /media each time I insert a new disk. Also, the mounting and unmounting process causes it's own problems, but I think that could be covered by a for loop that checks /mtab every few seconds or so.

Any help in figuring this out would be greatly appreciated.

T3RM1NVT0R 06-24-2011 04:44 PM

@ Reply
 
Hi there,

Give these steps a try:

1. vi /cdcopy
2. Put the following lines in the file:

mkdir /media/cddrive
mount /dev/cdrom /media/cddrive
cp -arv /media/cddrive/. /location_where_you_want_files_to_be_copied
umount /media/cddrive
rm -r -f /media/cddrive

3. After putting the above lines save the file and exit.
4. Change the permissions on the file to make it executable. chmod 777 /cdcopy
5. Whenever you want to execute the file, execute using ./cdcopy

I hope this helps.

valunthar 06-24-2011 05:27 PM

hmm, that does look promising, though I think would do something like this instead

if `cat /dev/mtab | grep /dev/sr0` = true
umount /dev/sr0
mount /dev/sr0 /media/cddrive
cp -arv /media/cddrive/. /Archive
echo "The CD has finished copying"
umount /dev/sr0
end if

Though I'm not completely certain whether that if condition would actually work in bash as currently written. Now the only thing left to figure out is to get the script to automatically run whenever a disc is inserted. A possible solution would be polling mtab, but I'm not quite sure how to go about doing it. Also, some kind of gtk notification and ejecting the cd-rom tray when it's finished copying would be useful additions.

EDIT: Now this is weird, I tried that script without the if portion and things seemed to copy properly, except for the fact that all of the files copied had invalid encoding appended to the file name. Any ideas on why that happened?


All times are GMT -5. The time now is 06:28 PM.