| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 | 
							- #!/bin/bash
 
- sendEmail() {
 
- # sendEmail $to $from $pass $subject $host $port $message
 
- 	if [ $# -ne 7 ]; then
 
- 		echo -en "ERROR:\tError interno en sendEmail.\n"
 
- 		exit 1
 
- 	fi
 
- 	to=$1
 
- 	shift
 
- 	from=$1
 
- 	shift
 
- 	pass=$1
 
- 	shift
 
- 	subject=$1
 
- 	shift
 
- 	host=$1
 
- 	shift
 
- 	port=$1
 
- 	shift
 
- 	message=$@
 
- 	echo -en "$message" | mailx -Ssendwait -s "$subject" -S smtp-use-starttls -S smtp-auth=login -S smtp=smtp://$host:$port -S from="$from" -S smtp-auth-user="$from" -S smtp-auth-password="$pass" $to > /dev/null 2>&1
 
- 	return $?
 
- 	unset to from pass subject host port message
 
- }
 
- getVirtualHosts() {
 
- # getVirtualHost $virtualHostPath
 
- 	if [ ! -d $1 ];then
 
- 		echo -en "ERROR:\tEl directorio \"$1\" no existe.\n"
 
- 		exit 1
 
- 	fi
 
- 	cont=1
 
- 	for virtualHost in $(find -L "$1" -type f);do
 
- 		grep ^[[:space:]]*auth_basic "$virtualHost" > /dev/null 2>&1
 
- 		if [ $? -eq 0 ];then
 
- 			# Si tiene la directiva "auth_basic" activada no lo comprobamos
 
- 			continue
 
- 		fi
 
- 		linea=$(grep ^[[:space:]]*server_name "$virtualHost")
 
- 		if [ $? -ne 0 ];then
 
- 			# Si no tiene la directiva "server_name" no lo comprobamos
 
- 			continue
 
- 		fi
 
- 		for hostname in $linea;do
 
- 			hostname=$(echo "$hostname" | sed 's/;//g')
 
- 			if [ $hostname != "server_name" ] && [ $hostname != "localhost" ];then
 
- 				hostnames[$cont]=$hostname
 
- 				cont=$((cont+1))
 
- 			fi
 
- 		done
 
- 	done
 
- 	# Eliminar repetidos
 
- 	hostnames=($(echo "${hostnames[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
 
- 	unset linea cont hostname
 
- }
 
- checkHostname() {
 
- # checkHostname $domain
 
- 	if [ $# -ne 1 ];then
 
- 		echo -en "ERROR:\tError interno en checkHostname.\n"
 
- 		exit 1
 
- 	fi
 
- 	domain=$1
 
- 	httpCode=$(curl -L -s -o /dev/null -w "%{http_code}" "$domain")
 
- 	case $httpCode in
 
- 		2[0-9][0-9])
 
- 			# Sitio Disponible
 
- 			return 0
 
- 			;;
 
- 		*)
 
- 			# Se ha producido algún error
 
- 			return 1
 
- 			;;
 
- 	esac
 
- }
 
- # Variables iniciales
 
- hostnames=""
 
- hostnamesFail=""
 
- echo -en $(date +'[%Y-%m-%d] %H:%M:%S')" Comprobando Virtual Hosts...\n"
 
- getVirtualHosts "/etc/nginx/sites-enabled/"
 
- for hostname in $hostnames;do
 
- 	checkHostname $hostname
 
- 	if [ $? -ne 0 ];then
 
- 		# Este dominio no está disponible
 
- 		echo -en "* \"$hostname\"\t\tNO ESTÁ DISPONIBLE.\n"
 
- 		hostnamesFail=$hostnameFail"* ""$hostname"" NO ESTÁ DISPONIBLE.\n"
 
- 	else
 
- 		echo -en "* \"$hostname\"\t\t ESTÁ DISPONIBLE.\n"
 
- 	fi
 
- done
 
- if [ ! -z $hostnamesFail ];then
 
- 	echo -en "Enviando informe por email a \$TO..."
 
- 	#sendEmail
 
- fi
 
 
  |