Skip to content

Instantly share code, notes, and snippets.

@mahaverick
Last active June 27, 2017 10:32
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 mahaverick/764af1de9d2137b1622207028416942e to your computer and use it in GitHub Desktop.
Save mahaverick/764af1de9d2137b1622207028416942e to your computer and use it in GitHub Desktop.
#!/bin/bash
# environment credentials
host=127.0.0.1
user=root
password=
database=test
# filename that you want to read :
file=$PWD/entries.txt
# checks whether parameter is passed or not :
: ${1?"Error! domain parameter is missing"}
parameter=$1
# sql connection string :
sqlin="mysql -u$user -p$password -h $host $database"
# check domain and get the id :
domain_check () {
$sqlin -N -B -e "SELECT id FROM domains WHERE name LIKE '$parameter'"
}
id=$(domain_check)
echo "id is $id"
if [[ -z $id ]]; then
echo " '${1}' domain does not exist in the table"
fi
# read from file and insert into db :
while read line; do
row=($line)
echo "INSERT INTO \`records\` (domain_id, name, type, content, ttl, prio, change_date) VALUES ($id, '${row[0]}.$parameter', '${row[1]}', '${row[2]}', 14400, 0, $(date +%s));" | $sqlin
done < $file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment