Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement