Muhajreen
asked on
Inserting file details into MySQL in CentOS
Hello experts,
I have thousands of files stored in this location in a CentOs server:
/var/source/
All file names are like this:
123_45678_2013_11_29_15_45 _30.gsm
This file name represents two numbers (123 and 45678) and a full date (2013/11/29) and a time (15:45:30)
I have a MySQL database named (filedb). A table named (files) has the following columns:
id ===== is a sequential number
source ===== is 123
destination ===== is 45678
date ==== is 11/29/2013
time ==== is 15:45:30
file ==== is the file name 123_45678_2013_11_29_15_45 _30.gsm
note ==== is an empty field
I need a script which should insert an entry to the (filedb) database for each file in the /var/source/ directory.
Note that the first two sections (123) and (45678) can vary in length. They may be 3,4,5 or more digits. The only wan to recognise sections is by underscores.
I have already setup a username and a password for accessing the MySQL database.
Would any body write the required script for me?
Thanks in advance.
I have thousands of files stored in this location in a CentOs server:
/var/source/
All file names are like this:
123_45678_2013_11_29_15_45
This file name represents two numbers (123 and 45678) and a full date (2013/11/29) and a time (15:45:30)
I have a MySQL database named (filedb). A table named (files) has the following columns:
id ===== is a sequential number
source ===== is 123
destination ===== is 45678
date ==== is 11/29/2013
time ==== is 15:45:30
file ==== is the file name 123_45678_2013_11_29_15_45
note ==== is an empty field
I need a script which should insert an entry to the (filedb) database for each file in the /var/source/ directory.
Note that the first two sections (123) and (45678) can vary in length. They may be 3,4,5 or more digits. The only wan to recognise sections is by underscores.
I have already setup a username and a password for accessing the MySQL database.
Would any body write the required script for me?
Thanks in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks to both of you.
For ease of understanding I will try the script of GaryC123 which came first.
Can anybody please give me the exact ${myvar[?]} values which should give the following values in order:
null
source
destination
date
time
file
note
The give values above don't present date nor time nor file.
For ease of understanding I will try the script of GaryC123 which came first.
Can anybody please give me the exact ${myvar[?]} values which should give the following values in order:
null
source
destination
date
time
file
note
The give values above don't present date nor time nor file.
ASKER
Thank you arnold. I have just tried your solution and it worked perfectly.
Open in new window