Created
January 31, 2020 10:47
-
-
Save robincher/957929dc823244de394568c18a23eaa6 to your computer and use it in GitHub Desktop.
Insert database records from text file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "Please enter database Password:" | |
read DB_PASSWD | |
if [ -z "DB_PASSWD" ]; then | |
echo "Please DB Password" | |
exit 1 | |
fi | |
echo "Logging into MySQL remotely..." | |
DB_USER="apex_svc" | |
DB_NAME="" | |
DB_HOST="" | |
TABLE=''; | |
while IFS=, read hostname clusterID; do | |
uuid=$(uuidgen | awk '{print tolower($0)}') | |
echo "$uuid" | |
echo "$hostname" | |
statement="INSERT INTO ${TABLE} (id, name, template, \`key\`, mgtFQDN, prodFQDN,subsystemStates,buildingState,createdBy,updatedBy,deletedBy,createdAt,updatedAt,deletedAt,ndClusterId) | |
VALUES ('${uuid}','${hostname}',NULL,'${hostname}','${hostname}.dc.mgmt','${hostname}.apex.lab',NULL,NULL,'[email protected]','[email protected]' | |
,NULL,'2018-01-29 05:51:40','2018-01-29 05:51:40',NULL,'${clusterID}');" | |
mysql --user=$DB_USER --password=$DB_PASSWD -h $DB_HOST -P 3306 -D $DB_NAME -e "$statement" | |
done < nds.txt | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nd-pvt6,a9f670ee-a490-4c24-b793-ff3f848f4738 | |
nd-pvt7,a9f670ee-a490-4c24-b793-ff3f848f4738 | |
nd-pvt8,a9f670ee-a490-4c24-b793-ff3f848f4738 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment