I am working trough some legacy code which does not work, I came across a part that is causing problems. I was hoping some one could help me out and fill me in on what is the exact functionality of this small part of the script and what could cause it to fail/not execute. If I run the first .sql file on command line, everything works great and I am using the same sql-logins as the script.
I have an update.sh file, which is run every night and takes care of updating customer info. How ever when we add customers to the file where it reads the data it fails to generate new database and stored procedure instances.
code snippet:
#!/bin/bash
mysql_host="localhost"
mysql_id="root"
mysql_pwd="sudopwd"
read_dom () {
local IFS=\>
read -d \< ENTITY CONTENT
}
.
Some functioning code
.
.
Here is the part that does not work
sed -i "s/tk[0-9]*;/tk$company_id;/1i" resources/sql/create_tk.sql
mysql -h $mysql_host -u $mysql_id "-p$mysql_pwd" < resources/sql/create_tk.sql
sed -i "s/tk[0-9]*/tk$company_id/gi" resources/sql/load_data_tk.sql
mysql -h $mysql_host -u $mysql_id "-p$mysql_pwd"< resources/sql/load_data_tk.sql
fi
done < info.xml
EN_MO=$(date +%s)
DIFF_MO=$[$EN_MO-$ST_MO]
C_DATE=$(date +"%Y%m%d%H%M")
If I understand correctly the first part -i means modify(change database in use in the script) create_tk.sql.
/s means that it is done recursively to each company
/1i means keep the tk[0-9]*;/tk$company_id; part of the string? and Insert the content?
/gi something to do with hold and pattern spaces? and Insert the content?
I would appreciate it really much if someone could clarify the exact meaning of this snippet and point out what could cause not being able to fulfill its function.
Thanks for the help everyone.
mysql -h $mysql_host -u $mysql_id -p $mysql_pwd
. Also quoting mysql_pwd is sending the literal $mysql_pwd as the password.