Advertisement
sergio_educacionit

anunciame.sh

May 23rd, 2023
1,026
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.78 KB | None | 1 0
  1. #!/bin/bash
  2.  
  3. frontend_server=<ip servidor de frontend o balencador>
  4.  
  5. local_ip=$(hostname -I | cut -d " " -f 1)
  6.  
  7. pool_file=/ruta/al/fichero/servidores
  8.  
  9.  
  10. # Si la ip que voy a enviar ya esta registrada en el remoto
  11. # entonces no deberia de enviarla
  12.  
  13. if ssh root@${frontend_server} "cat ${pool_file}" | grep ${local_ip} > /dev/null;then
  14.  
  15.     # si el grep encuentra que la direccion ip ya esta en el fichero
  16.     # remoto entonces no deberia de hacer nada
  17.     # a lo sumo podemos crear un registro de la accion.
  18.  
  19.     echo $(date) - La direccion ya se encuentra en el remoto. >> /root/anunciame.log
  20.  
  21. else
  22.     # si grep no encuentra la direccion ip local en el fichero remoto, la registra.
  23.  
  24.     echo "server ${local_ip};" | ssh root@${frontend_server} "cat >> $pool_file, systemctl reload nginx"
  25.  
  26. fi
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement