Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # environment credentials
  4.  
  5. host=127.0.0.1
  6. user=root
  7. password=
  8. database=test
  9.  
  10. # filename that you want to read :
  11. file=$PWD/entries.txt
  12.  
  13. # checks whether parameter is passed or not :
  14. : ${1?"Error! domain parameter is missing"}
  15. parameter=$1
  16.  
  17. # sql connection string :
  18. sqlin="mysql -u$user -p$password -h $host $database"
  19.  
  20. # check domain and get the id :
  21. domain_check () {
  22. $sqlin -N -B -e "SELECT id FROM domains WHERE name LIKE '$parameter'"
  23. }
  24.  
  25. id=$(domain_check)
  26.  
  27. echo "id is $id"
  28.  
  29. if [[ -z $id ]]; then
  30. echo " '${1}' domain does not exist in the table"
  31. fi
  32.  
  33. # read from file and insert into db :
  34.  
  35. while read line; do
  36. row=($line)
  37. 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
  38. done < $file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement