Guest User

Untitled

a guest
Feb 23rd, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [ "$UID" -ne 0 ];
  4. then
  5. echo "Run this script as root user only"
  6. exit 100
  7. fi
  8.  
  9. while getopts ":p:f:u:" o; do
  10. case "${o}" in
  11. p)
  12. password=${OPTARG}
  13. ;;
  14. f)
  15. file_path=${OPTARG}
  16. ;;
  17. u)
  18. user=${OPTARG}
  19. ;;
  20. *)
  21. echo "Enter password with -p and id_rsa.pub file path with -f"
  22. exit 101
  23. ;;
  24. esac
  25. done
  26. array=`grep -oE "\b^[^#]([0-9]{1,3}\.){3}[0-9]{1,3}\b" /etc/ansible/hosts`
  27. for ip_add in $array ;
  28. do
  29. sshpass -p "$password" ssh-copy-id -i $file_path -o StrictHostKeyChecking=no "$user"@"$ip_add" -f
  30. done
Add Comment
Please, Sign In to add comment