Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #include variables from config file
  4.  
  5. source /home/porta-one/def_conf.ini
  6.  
  7. #check whether the script is run as root/sudo
  8.  
  9. is_root ()
  10. {
  11. whoami | grep "root" > /dev/null
  12.  
  13. if [ $? -eq 1 ]
  14. then
  15. echo "You must run script as root";
  16. exit;
  17. fi
  18. }
  19.  
  20. parse_options ()
  21. {
  22. echo "The following options will be used for replication restoration:
  23. database replicate from: $master_host
  24. database replicate to: $slave_host"
  25.  
  26. i="0"
  27.  
  28. while [ $i -lt 3 ]
  29. do
  30. read -p "Do you agree? (Y/N) " confirm
  31. if printf "%s\n" "$confirm" | grep -Eq "$(locale yesexpr)"
  32. then
  33. echo "Confirmed..."
  34. i=3
  35. elif printf "%s\n" "$confirm" | grep -Eq "$(locale noexpr)"
  36. then
  37. echo "Change def_conf.ini" && exit 1
  38. i=3
  39. else
  40. echo "Press Y or N"
  41. i=$[$i+1]
  42. fi
  43. done
  44. }
  45.  
  46. is_configurator_ssh ()
  47. {
  48. conf_ip=`/home/porta-configurator/bin/cfgctl.pl -c get_configurator_addr`
  49. current_ip=`hostname -I | awk '{print $1}'`
  50.  
  51. if [ $conf_ip == $current_ip ]
  52. then
  53. ssh_conn=""
  54. else
  55. ssh_conn=($rsh_porta $conf_ip)
  56. fi
  57. }
  58.  
  59. mysql_cmd ()
  60. {
  61. slave_ip=`mysql -u root porta-configurator -Nse "select ip from Servers where i_server in (select i_server from Instances where name like \"$slave_host%\" and i_configuration in (select max(i_configuration) from Instances));"`
  62.  
  63. master_ip=`mysql -u root porta-configurator -Nse "select ip from Servers where i_server in (select i_server from Instances where name like \"$master_host%\" and i_configuration in (select max(i_configuration) from Instances));"`
  64.  
  65. web_ip=(`mysql -u root porta-configurator -Nse "select ip from Servers where i_server in (select i_server from Instances where name like \"$web_host%\" and i_configuration in (select max(i_configuration) from Instances));"`)
  66.  
  67. echo "slave: $slave_ip, master: $master_ip, web: $web_ip"
  68. }
  69.  
  70. is_root
  71. parse_options
  72. is_configurator_ssh
  73.  
  74. $ssh_conn mysql_cmd
  75.  
  76. echo "slave: $slave_ip, master: $master_ip, web: $web_ip"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement