Here's a variant of the same theme: distribute.sh
distribute.sh
#!/bin/bash [ $# -eq 0 ] \ && { echo "${CYAN} Usage ${WHITE} $(basename $0) /path/to/file ${YELLOW}[/destination/directory]${RESTORE}" exit } [ -f "$1" -a ! -d "$1" ] \ && { SCP="scp" FILE="$(realpath $1)" shift } \ || { [ -d "$1" ] \ && { RECUR="recursive" SCP="scp -r" FILE="$(realpath $1)" shift } \ || { echo "${RED} Error: ${WHITE} Unknown file or directory.${RESTORE}" exit 1 } } [ $# -gt 0 ] \ && { DESTDIR="$(realpath $1)/" } \ || { DESTDIR="$(dirname $(realpath ${FILE}))/" } echo -e "${WHITE}Copying ${RECUR}\nFrom: ${YELLOW}${FILE}\n${WHITE}To: ${YELLOW}${DESTDIR}${RESTORE}" for DEST in $(cat ~/.ssh/authorized_keys | cut -f 3 -d ' ' | tr -d ' ' ) do DESTUSER=$( echo ${DEST} | cut -f 1 -d '@' | tr -d '[:space:]' ) DESTHOST=$( echo ${DEST} | cut -f 2 -d '@' | tr -d '[:space:]' ) echo -n "${CYAN}===>${WHITE} ${DESTUSER}${YELLOW} @${WHITE} ${DESTHOST}" if ping -c 1 -w 2 -nq ${DESTHOST} > /dev/null 2>&1 then echo " ${GREEN}OK${RESTORE}" else echo " ${RED}NOT OK${RESTORE}" continue fi echo "${CYAN} Copy ${WHITE}${FILE} to ${DESTDIR}" $SCP ${FILE} ${DESTHOST}:${DESTDIR} done
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Here's a variant of the same theme:
distribute.sh