Hi,
I'm not a pro bashscript writer but I'm learning and want to learn about my mistakes.
In the next script I have an error on rule 6 but I can't find what I'm doing wrong ...
I daily receive a file xml.xml and have to import it in an mysql database in a few existing tables.
Code:
#!/bin/bash
FILE="/transfer/store/xml.xml"
RESULT=$(xmlstarlet sel -t -v "count(//Appointment)" $FILE)
_DB_TABLE_PERSONS="persons"
_DB_TABLE_INVITATIONS="invitiations"
FOR (( i=0; i<$RESULT; i++ )) ; DO
PFIRST_NAME="$(xmlstarlet sel -t -v //Appointment[${i}+1]/person-info/data1 $FILE)"
PLAST_NAME="$(xmlstarlet sel -t -v //Appointment[${i}+1]/person-info/data2 $FILE)"
PADDRESS="$(xmlstarlet sel -t -v //Appointment[${i}+1]/person-info/data3 $FILE)"
PTELEPHONE="$(xmlstarlet sel -t -v //Appointment[${i}+1]/person-info/data4 $FILE)"
PEMAIL="$(xmlstarlet sel -t -v //Appointment[${i}+1]/person-info/email $FILE)"
VALUES(NULL,'${FIRST_NAME}','${LAST_NAME}','${ADDRESS}','${TELEPHONE}','${EMAIL}');"
QUERY="INSERT INTO ${_DB_TABLE_PERSONS} ('id','first_name','last_name','address','telephone','email') VALUES(NULL,'${PFIRST_NAME}','${PLAST_NAME}','${PADDRESS}','${PTELEPHONE}','${PEMAIL}');"
mysql --host=10.1.12.69 --user=test --password=test --database=test < $QUERY
ID_PERSONS=$(mysql --host=10.1.12.69 --user=test --password=test --database=test -se "SELECT LAST_INSERT_ID()")
IREMARK="$(xmlstarlet sel -t -v //Appointment[${i}+1]/person-info/data5 $FILE)"
ELAST_NAME="$(xmlstarlet sel -t -v //Appointment[${i}+1]/transfer-info/name $FILE)"
ID_EMPLOYEES=$(mysql --host=10.1.12.69 --user=test --password=test --database=test -se "SELECT id FROM employees WHERE last_name=${ELAST_NAME}")
LNAME="$(xmlstarlet sel -t -v //Appointment[${i}+1]/transfer-info/locatiebenaming $FILE)"
ID_LOCATIONS=$(mysql --host=10.1.12.69 --user=test --password=test --database=test -se "SELECT id FROM locations WHERE UCASE(name) like '%${ELAST_NAME}%'")
ID_I_TEMP="$(xmlstarlet sel -t -v //Appointment[${i}+1]/Date $FILE)"
IT_I_TEMP="$(xmlstarlet sel -t -v //Appointment[${i}+1]/Time/Begin $FILE)"
IDATE_INVITATION=${ID_I_TEMP:0:4}-${ID_I_TEMP:4:2}-${ID_I_TEMP:6:2}
IEXPIRATION_DATE=${IT_I_TEMP:0:2}-${IT_I_TEMP:2:2}
QUERY="INSERT INTO ${_DB_TABLE_INVITATIONS} ('id','person','employee','location','date_invitation','time_invitation','notification','remark') VALUES(NULL,'${PFIRST_NAME}','${PLAST_NAME}','${PADDRESS}','${PTELEPHONE}','${PEMAIL}');"
mysql --host=10.1.12.69 --user=test --password=test --database=test < $QUERY
DONE
If someone out there could help me out with this problem. I would really
appreciate it.
My requirement is :Read XML and put data in Test.txt file.Using Shell script(bourn)
My xml file:
<root>
<header>
<HeaderData1>header1</HeaderData1>
<HeaderData2>header2</HeaderData2>... (0 Replies)
I'm an absolute newbie for unix...
For my work, I have to import a xml file in our system (jsp+sql) via putty telnet.
Once i have copied the file in the right directory, I launch this command:
./thisImport -i input/thisImport/newimport.20071130.xml -l 10 -t
this is a test (as you can see),... (1 Reply)
Hi,
I have an XML file with following structure. Between following tags I have pipedelimited records with newline characters (Data1|1|2|3)
<!]>
I need to read the data between above tags so that my output is a flat file with pipedelimited records.
<BOS>
<Header>
<TTC>ABC</TTC> ... (9 Replies)
Hi,
Is there any way that mysql query reads the content from a text file which has data in the below format:
1,2,3,4,5
and selects matched data from another table.
ie I have a table named xyz which has same ids as in that file.
I want this query to get count of the ids from xyz file by... (6 Replies)
Hi all,
I'm trying to import some functions I have saved in a file named
functions.sh into a different script (protocol.sh). Can anybody show
me how to do this? I tried source functions.sh as I would do at the
terminal but source command cannot be found from within the script
protocol.sh.
... (2 Replies)
Hi everybody, I need the help of the Unix community once again :)
I have some code which queries an XML feed and displays the results for me. I would like to enter the XML output in to my database, but I am having trouble passing the variables while INSERTing.
Here is my code that I need to... (0 Replies)
Hey, I'm new here. Basically, I'm trying to make a bash script that affects a file of my choice.
What I want to do is $./script.sh /path/to/file.jpg and then the bash script will know that variable=/path/to/file.jpg
Thanks! (4 Replies)
Hi All, In my account with csh shell, there are lots of env variables set and I want to import those all to bash in one stroke, is there any way to do it ? Thanks, D (1 Reply)
Hello,
Sorry for my bad english.
I need to improve performance in project managing large data, these data are exported to a MySql from XML.
Now I use PHP (XMLReader ()) to do this job.
I need a faster way to do this process.
Which do you think is the best way?
Example:
(the item... (2 Replies)