|
@@ -19,12 +19,17 @@ sendEmail() {
|
|
port=$1
|
|
port=$1
|
|
shift
|
|
shift
|
|
message=$@
|
|
message=$@
|
|
- echo -en "$message" | mailx -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 >> $logFile 2>&1
|
|
+ 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
|
|
unset to from pass subject host port message
|
|
}
|
|
}
|
|
|
|
|
|
getVirtualHosts() {
|
|
getVirtualHosts() {
|
|
# getVirtualHost $virtualHostPath
|
|
# getVirtualHost $virtualHostPath
|
|
|
|
+ if [ ! -d $1 ];then
|
|
|
|
+ echo -en "ERROR:\tEl directorio \"$1\" no existe.\n"
|
|
|
|
+ exit 1
|
|
|
|
+ fi
|
|
cont=1
|
|
cont=1
|
|
for virtualHost in $(find -L "$1" -type f);do
|
|
for virtualHost in $(find -L "$1" -type f);do
|
|
grep ^[[:space:]]*auth_basic "$virtualHost" > /dev/null 2>&1
|
|
grep ^[[:space:]]*auth_basic "$virtualHost" > /dev/null 2>&1
|
|
@@ -47,12 +52,47 @@ getVirtualHosts() {
|
|
done
|
|
done
|
|
# Eliminar repetidos
|
|
# Eliminar repetidos
|
|
hostnames=($(echo "${hostnames[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
|
|
hostnames=($(echo "${hostnames[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
|
|
- echo -en "Hostnames: ""${hostnames[@]}""\n"
|
|
|
|
unset linea cont hostname
|
|
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
|
|
# Variables iniciales
|
|
-logFile="."$(basename $0)".log"
|
|
|
|
hostnames=""
|
|
hostnames=""
|
|
|
|
+hostnamesFail=""
|
|
|
|
|
|
|
|
+echo -en $(date +'[%Y-%m-%d] %H:%M:%S')" Comprobando Virtual Hosts...\n"
|
|
getVirtualHosts "/etc/nginx/sites-enabled/"
|
|
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
|