cr.dat : fichero que contiene intro o retorno de carro
—————Centinela.cmd : cortar aquí———————-
@echo off
:start
cls
echo ***********************************************************
echo Centinela o Control de red *
echo Utilidad para la creación de alarmas administrativas *
echo ante la pérdida de conexión con un host de la red local *
echo Javier Castañón 2.003/2.004 *
echo ***********************************************************
if ‘%1’==’?’ goto Ayuda
Rem Averiguamos el sistema operativo
Rem lo implemento para 2 casos WNT y OS/2
Rem que se daban en la red UCA de Aena
Rem entre 2.003 y 2.004
if ‘%OS%’==’Windows_NT’ set sistemaop=nt
if ‘%SYSTEM_INI%’==’C:\OS2\OS2SYS.INI’ set sistemaop=os2
echo Sistema Operativo = %sistemaop%
Rem setlocal…endlocal , Para os/2 mantiene intocadas las variables de entorno generales
if %sistemaop%==’os2′ SETLOCAL
Rem Break=on en entorno OS/2 , asegura poder cortar la ejecución por lotes con ctrl+c
Rem if %sistemaop%==’os2′ BREAK=ON
Rem Pero lo habilitamos para todos los casos, ya que Nt lo admite
BREAK=ON
set n=1
@if exist testigo.txt del testigo.txt >nul
goto %n%
:rutina
@if exist testigo.txt del testigo.txt >nul
if %sistemaop%==’nt’ goto nt
if %sistemaop%==’os2′ goto os2
:nt
set ERRORLEVEL=
ping %iphost% -n 3 > testigo.txt
find /C «recibidos = 0» testigo.txt
Rem también valdria «perdidos =3»
goto alertant%ERRORLEVEL%
Rem Hay alerta errorlevel=0
:alertant0
Rem Mandar alerta a fichero con nombre e ip de el host de la alerta
Rem si no existe el fichero lo crea
if Not exist Alerta_%namehost%.txt type nul > Alerta_%namehost%.txt
echo ****************************************************>>Alerta_%namehost%.txt
echo Alerta administrativa_El host %namehost% %iphost% No responde >>Alerta_%namehost%.txt
Rem Sellamos la alerta con fecha y hora del suceso
Rem (cr.dat fichero con retorno de carro o intro)
date < cr.dat | find «L»>>Alerta_%namehost%.txt
time < cr.dat | find «L»>>Alerta_%namehost%.txt
echo ****************************************************>>Alerta_%namehost%.txt
Rem mandamos un mensage al host puestodecontrol
net send puestodecontrol Alerta en %namehost% %iphost%
rem ********* Otras ideas ******************************************************
rem Habria que crear un directorio compartido en un puesto para mandar las alertas
rem por ejemplo \\puestodecontrol\alerta
rem y cada dia controlar con script o manualmente las alertas y borrar si fuese necesario
rem conprobamos que la ud remota k esté correctamente mapeada
rem if Not exist k:\controlmap net use k: /Delete /Yes
rem if Not exist k:\controlmap net use k: \\puestodecontrol\alerta
rem if Not exist K:\controlmap type nul > k:\controlmap
rem lo copiamos en alerta
rem type testigo.txt >> Alerta_%namehost%.txt
rem copy Alerta_%namehost%.txt k:\Alerta_%namehost%.txt /Y
rem ********************************************************************************
goto %n%
Rem No hay alerta errorlevel=1
:alertant1
goto %n%
: os2
set ERRORLEVEL =»
ping %iphost% 56 3 > testigo.txt
find /C «0 packets received» testigo.txt
goto alertaos2%ERRORLEVEL%
:alertaos20
rem mandar alerta administrativa a fichero con nombre del host, donde guardará todas las alertas
if Not exist Alerta_%namehost%.txt type nul >Alerta_%namehost%.txt
echo ******************************************************************** >>Alerta_%namehost%.txt
echo Alerta Administrativa _ El host %namehost% %iphost% No responde >>Alerta_%namehost%.txt
rem sellamos la alerta con fecha y hora del suceso ( cr.dat fichero con retorno de carro o intro)
date < cr.dat | find «L» >>Alerta_%namehost%.txt
time < cr.dat | find «L» >>Alerta_%namehost%.txt
echo ******************************************************************** >>Alerta_%namehost%.txt
:alertaos21
goto %n%
:begin
cls
echo ***********************************************************
echo Centinela o Control de red *
echo Utilidad para la creación de alarmas administrativas *
echo ante la pérdida de conexión con un host de la red local *
echo Javier Castañón 2.003/2.004 *
echo ***********************************************************
:1
set iphost=1.1.1.1
set namehost=gw
set n=2
goto rutina
:2
set iphost=192.168.50.100
set namehost=Mostrador100
set n=3
goto rutina
:3
set iphost=2.2.2.2
set namehost=puesto2
set n=4
goto rutina
:4
if %sistemaop%==’os2′ ENDLOCAL
goto start
rem ….
rem :n
rem …
:fin
exit
:Ayuda
echo Aqui iria la descripción de la ayuda
echo ….
REM By JavCasta.
————–cortar aquí———————–
Deja un comentario