Page MenuHomePhabricator
Paste P11280

zarcillo-add
ActivePublic

Authored by Kormat on Fri, May 22, 9:00 AM.
#!/bin/bash
if [ $# -eq 0 ]; then
echo "Usage:"
echo " ${0##*/} FQDN PORT RACK SECTION [SECTION ..]"
exit 0
fi
fqdn=${1:?}; shift
port=${1:?}; shift
rack=${1:?}; shift
sections="$@"
hostname=${fqdn%%.*}
name=$hostname
[ $port -eq 3306 ] || name=$hostname:$port
dc=$(echo $fqdn | cut -f2 -d.)
set -exu
{
echo "START TRANSACTION;"
echo "INSERT INTO instances (name, server, port) VALUES ('$name', '$fqdn', $port);"
echo "INSERT INTO servers (fqdn, hostname, dc, rack) VALUES ('$fqdn', '$hostname', '$dc', '$rack');"
for i in $sections; do
echo "INSERT INTO section_instances (instance, section) VALUES ('$name', '$i');"
done
echo "COMMIT;"
} | sudo -i mysql.py -BE -h db2093 zarcillo

Event Timeline

Kormat created this paste.Fri, May 22, 9:00 AM