Skip to content

Instantly share code, notes, and snippets.

@robincher
Created January 31, 2020 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robincher/957929dc823244de394568c18a23eaa6 to your computer and use it in GitHub Desktop.
Save robincher/957929dc823244de394568c18a23eaa6 to your computer and use it in GitHub Desktop.
Insert database records from text file
#!/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,'apex01@idahive.sg','apex01@idahive.sg'
,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
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