Last active
June 27, 2017 10:32
-
-
Save mahaverick/764af1de9d2137b1622207028416942e to your computer and use it in GitHub Desktop.
This file contains 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 | |
# 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