LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Bash or Perl example: copying data from a CD/DVD, to hard drive. (https://www.linuxquestions.org/questions/programming-9/bash-or-perl-example-copying-data-from-a-cd-dvd-to-hard-drive-805907/)

bluesword1969 05-04-2010 01:31 PM

Bash or Perl example: copying data from a CD/DVD, to hard drive.
 
Seeking a decent Perl or Bash script or hack used to copy data from a CD/DVD to local or even remote hard drive/storage.

Thanks!

Sergei Steshenko 05-04-2010 01:39 PM

Quote:

Originally Posted by bluesword1969 (Post 3957164)
Seeking a decent Perl or Bash script or hack used to copy data from a CD/DVD to local or even remote hard drive/storage.

Thanks!

What other than 'cp' do you need ?

PMP 05-04-2010 01:41 PM

From perl or shell

Mount the drive.
Copy the data.
unmount the drive

bluesword1969 05-04-2010 02:04 PM

Examples, please! Let me elaborate. Let's say you're copying items from a CD/DVD, to be later imported to say, MySQL, or something of the sort.

What's a good script that would copy the data, from the CD/DVD, into a directory in a sort of format like this:

cp -v /<data from CD/DVD> <your initials>-<the date>-<the directory name>

A pretty format that could be later imported to MySQL, or something of that nature.

Just looking for ideas.

Thanks!

Sergei Steshenko 05-04-2010 02:20 PM

Quote:

Originally Posted by bluesword1969 (Post 3957226)
Examples, please! Let me elaborate. Let's say you're copying items from a CD/DVD, to be later imported to say, MySQL, or something of the sort.

What's a good script that would copy the data, from the CD/DVD, into a directory in a sort of format like this:

cp -v /<data from CD/DVD> <your initials>-<the date>-<the directory name>

A pretty format that could be later imported to MySQL, or something of that nature.

Just looking for ideas.

Thanks!

Before you ask for examples maybe you'll formulate technical requirements ?

For example, who is "you" in <your initials> ? Current user ID ? User ID of the file owner on CD/DVD ?

What is <the date> ? I.e. file modification date on CD/DVD ? Current date ? Date entered on command line ?

What is <the directory name> ? I.e. what directory are you talking about ? Where should its name come from ?

Why are you asking about CD/DVD ? How data on mounted CD/DVD is different from any other data on disk (except for being read-only) ?

...

Have you read 'man cp' ? Do you know how 'cp -r ...' works ?

bluesword1969 05-04-2010 02:34 PM

Quote:

Originally Posted by Sergei Steshenko (Post 3957240)
Before you ask for examples maybe you'll formulate technical requirements ?

For example, who is "you" in <your initials> ? Current user ID ? User ID of the file owner on CD/DVD ?

What is <the date> ? I.e. file modification date on CD/DVD ? Current date ? Date entered on command line ?

What is <the directory name> ? I.e. what directory are you talking about ? Where should its name come from ?

Why are you asking about CD/DVD ? How data on mounted CD/DVD is different from any other data on disk (except for being read-only) ?

...

Have you read 'man cp' ? Do you know how 'cp -r ...' works ?

- The "me", is my current user ID: bluesword1969
- The "date" would be the current date.
- The directory name would be derived from the directory on the CD/DVD. So for instance:

US_EN_Speaker_data_vol1

This is a typical directory name that I find on a lot of the data CD's and DVD's that I encounter.

- It's not the mounting of the CD's and DVD's I'm really worried about. I'm using GNOME, so any disc that I pop in gets auto-mounted. I just want to open a shell, and fire up a script that copies the data right from the disc.

- Yes, I know what cp (-r) does. :-)

Thanks!

Sergei Steshenko 05-04-2010 02:50 PM

Quote:

Originally Posted by bluesword1969 (Post 3957261)
- The "me", is my current user ID: bluesword1969
- The "date" would be the current date.
- The directory name would be derived from the directory on the CD/DVD. So for instance:

US_EN_Speaker_data_vol1

This is a typical directory name that I find on a lot of the data CD's and DVD's that I encounter.

- It's not the mounting of the CD's and DVD's I'm really worried about. I'm using GNOME, so any disc that I pop in gets auto-mounted. I just want to open a shell, and fire up a script that copies the data right from the disc.

- Yes, I know what cp (-r) does. :-)

Thanks!

Then in Perl there is getpw* functions (see 'perldoc perlfunc' for them) to get user ID. You might end up with
Code:

chomp(my $user = `whoami`);
though.

Read about 'File::Spec', 'File::Basename', 'File::Path', 'Cwd' Perl modules for efficient dealing with paths.

Regarding date - look for "Perl date time modules".

Sergei Steshenko 05-04-2010 02:55 PM

And, of course,

Code:

perldoc -f opendir
perldoc -f readdir
perldoc -f closedir
perldoc -f stat

.


All times are GMT -5. The time now is 02:40 PM.