#!/bin/bash -x
 
# copia mi backup en máquinas remotas.
 
# variables
RANGO="192.168.30"
N_COPIAS=3
MI_IP=`ip route | awk '/link/ {print $9}'`	# awk hace de grep, con /link/ "matcha" la linea y elimina el CR-LF
 
# funciones
conecta() 
{
	echo '*******************************'
	echo $1
	echo '*******************************'
 
	mkdir /mnt/temporal
	mount -t nfs $1:/home/backups /mnt/temporal
 
	if [ -f "/mnt/temporal/hostname.txt" ]; then
		NOMBRE=`cat /mnt/temporal/hostname.txt`
		# desmonto el directorio remoto
		umount /mnt/temporal
		# elimino el directorio "temporal" local
		rmdir /mnt/temporal
		# creo el nuevo punto de montaje
		mkdir /mnt/$NOMBRE
		mount -t nfs $1:/home/backups /mnt/$NOMBRE
	else
		NOMBRE='temporal'
	fi
 
	if [ ! -d "/mnt/$NOMBRE/d4" ]; then
		mkdir /mnt/$NOMBRE/d4
		if [ "$?" -ne "0" ]; then
			echo "el Kpullo tiene el NFS en RO o algo falla"
		fi
	fi
	cp -ur /home/backups/d4/* /mnt/$NOMBRE/d4
 
#	if [ ! -d "/mnt/$1" ]; then
#	fi
}
 
 
 
#aleatorio
	# 	SEMILLA=`date +%S`
	# IP_INICIO=$((SEMILLA*4))	# opción 1
	# IP_INICIO=`expr $SEMILLA\*4`	# opcion 2
IP_INICIO=`echo $(($RANDOM%254))`
 
 
for hosts in `nmap -sP $RANGO.$IP_INICIO-254, $RANGO.1-$IP_INICIO -exclude $MI_IP 2>/dev/null | grep "appears to be up" | awk '{print $2}'`
do
	RESULT=`rpcinfo -u $hosts nfs 2>/dev/null | grep -c "listo y a la espera"`
	if [ "$RESULT" -eq "1" ]; then
#		echo -n "NFS Responde $hosts"
		ISMOUNTHERE=`showmount -e $hosts | grep -c "^/home/backups "`
		if [ "$ISMOUNTHERE" -eq "1" ]; then
#			echo " Backups Available Here"
			conecta "$hosts";
		else
 
#			echo " Backups NOT Available"
			echo -n ""
		fi
	fi
done
  • info/cursos/lpic2/scripts/copia-remotos.txt
  • Darrera modificació: 15/08/2018 04:07
  • per mate