Configure automatic script in windows server

Dear Experts,
I have database running,on windows server 2003 and my database are going down frequently due to some oracle bug.

I need help to configure the automatic script which run's and check the database status, if database is down then send me email.

Thanks in Advance.

What Unix / Linux platform would you like the script to run on, since these are not the Windows Server 2003 forums...

Thanks for update, I understand. Appricatied and helpfull for me, if anybody have any info regarding this.

Thank you.

you can use vbscript and use WMI to retrive all the running process in the windows server and check whether your database is running or not.

For mail, you can use bmail or blat utilities.

if it is running as service, then you can start the service immediately by settings ( once it goes down )

Thanks for help, I'm new to this.If possible can you please provide me links or document so i can follow.

Not tested ...

save the file as check.vbs and run it through the command prompt using the cscript.exe check.vbs

http://www.computerperformance.co.uk/vbscript/wmi_process.htm

In the below code, i used the blat utitlity, check the blat webpage for more options and usage of blat.

you need to install using the -install option.

http://www.blat.net/examples/install&profile.html

 
' Process.vbs
' VBScript Win32_Process to discover which processes are running
' Author Guy Thomas http://computerperformance.co.uk/
' Version 1.4 - December 2010
' -------------------------------------------------------' 
Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strList
strComputer = "."
Found="NO"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _ 
& strComputer & "\root\cimv2") 
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process")
For Each objProcess in colProcess
'''''''''''''Check the Process Name'''''''''
IF trim(objProcess.Name) = "YOUR_PROCESS_NAME" THEN
Found="YES"
END IF
'''''''''''''END'''''''''
Next
IF Found = "NO" THEN
'Trigger the email - use blat or bmail utility
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "blat -to abcd@xyz.com -subject ""SQL Server process not running"" -body ""SQL Server process not running""", 1, True
'clear out wshshell variable
set wshShell = Nothing
END IF
WScript.Quit
' End of List Process Example VBScript

Thanks for update, In the code i'm facing issue details given below please suggest.

C:\Documents and Settings\Fareedm\Desktop>cscript.exe check.vbs
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Documents and Settings\Fareedm\Desktop\check.vbs(10, 1) Microsoft VBScript ru
ntime error: Variable is undefined: 'Found'

C:\Documents and Settings\Fareedm\Desktop>

change these two lines

 
Dim objWMIService, objProcess, colProcess
Dim strComputer, strList

to
 
Dim objWMIService, objProcess, colProcess,WshShell 
Dim strComputer, strList,Found

Also change the below line

 
 
set WshShell = Nothing

Thanks for update seems script is executing but the issue is i'm not reaciving the email while running the script.

C:\Documents and Settings\Fareedm\Desktop>Blat -install 192.168.100.204 3 FROMME
 25
SMTP server set to 192.168.100.204 on port 25 with user 3, retry FROMME time(s)
C:\Documents and Settings\Fareedm\Desktop>cscript.exe check.vbs
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Documents and Settings\Fareedm\Desktop>

Please advice.

can you put below line before the WScript.Quit and check what is the value of the Found variable.

msgbox Found

Also, you can print the process name ( inside the For Each loop) and check whether the expected process name is coming or not

 
For Each objProcess in colProcess
'''''''''''''Check the Process Name'''''''''
WSCript.Echo objProcess.Name
IF trim(objProcess.Name) = "YOUR_PROCESS_NAME" THEN
Found="YES"
END IF
'''''''''''''END'''''''''

Its showing the below process, and also opening the pop-up with saying "NO".

C:\Documents and Settings\Fareedm\Desktop>cscript.exe check.vbs
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.
System Idle Process
System
smss.exe
csrss.exe
winlogon.exe
services.exe
lsass.exe
svchost.exe
svchost.exe
MsMpEng.exe
svchost.exe
svchost.exe
svchost.exe
spoolsv.exe
svchost.exe
tomcat5.exe
svchost.exe
svchost.exe
winvnc4.exe
WLIDSVC.EXE
YahooAUService.exe
CcmExec.exe
wmiprvse.exe
explorer.exe
igfxsrvc.exe
hkcmd.exe
igfxpers.exe
msseces.exe
SearchProtection.exe
ctfmon.exe
Ymsgr_tray.exe
OUTLOOK.EXE
OSPPSVC.EXE
WLIDSVCM.EXE
wmiprvse.exe
TOAD.exe
iexplore.exe
iexplore.exe
iexplore.exe
notepad.exe
iexplore.exe
putty.exe
notepad.exe
firefox.exe
plugin-container.exe
notepad.exe
cmd.exe
notepad.exe
plugin-container.exe
cmd.exe
wuauclt.exe
wmiprvse.exe
cscript.exe

what process you are checking it ?

 
IF trim(objProcess.Name) = "YOUR_PROCESS_NAME" THEN

I'm sorry i din't change this line, I put the process name oracle and tried, seems issue is same, Because when i'm trying check the oracle process in task manager its not showing , when i'm doing

c:\> tasklist

from cmd level, its showing the oracle process.

Please advice.

try the below code.

change the highlighted to your process name

Also, give the full path for blat

dim WshShell
dim f,fso,Filename
Const ForReading = 1
Set WshShell = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
'run the command and redirect
WshShell.Run "cmd /c tasklist.exe |sort > C:\\tlist.txt", 2, True
Filename = "C:\\tlist.txt"
Set f = fso.OpenTextFile(FileName, ForReading, True)
FileText = f.ReadAll
f.close
IF InStr(FileText,"oracle.exe") = 0 Then
 'Trigger the email - use blat or bmail utility
 Set WshShell = WScript.CreateObject("WScript.Shell")
 WshShell.Run "blat -to abcd@xyz.com -subject ""SQL Server process not running"" -body ""SQL Server process not running""", 1, True
 'clear out wshshell variable
 set wshShell = Nothing
END IF
WScript.Quit

Dear Expert,

Thanks for your efford on this Issue,I'm very much happy to find valuble soulutions.

I tried the below given code but i'm not reaciving email with this.

Also tried option of check option, its showing the blank window.

 
msgbox Found
C:\Documents and Settings\Fareedm\Desktop>Blat -install 192.168.100.204 3 FROMME
 25
SMTP server set to 192.168.100.204 on port 25 with user 3, retry FROMME time(s)
C:\Documents and Settings\Fareedm\Desktop>cscript.exe check.vbs
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Documents and Settings\Fareedm\Desktop>

Code Writtend by me:-

 
Issue is :- Though the process is running,It is sending the emails.please suggest I beleive some thing wrong in if condition.
tasklist /FI "IMAGENAME eq notepad.exe" /NH
if "%ERRORLEVEL%"=="0" (
mailsend -d xxxx.local -smtp 192.16x.xx.xx -t fareedm@xxxx.xx -c fareedm@xxxx.xx -f oracle@123.ae -sub "Al" <results.txt   
) else (
 echo Found! logged files into results.txt
)

Thanks Alot,

use the below line in your blat, so that you can check why it is failed.

-log blat.log

I mentioned like this but i don't find the log file.

WshShell.Run "blat -to fareedm@xxx.xx-subject ""SQL Server process not running"" -log blat.log -body ""SQL Server process not running""", 1, True]

did you give the fullpath for the blat ? ( i already mentioned in my old post )

 
WshShell.Run "/full/path/blat -to fareedm@xxx.xx -log blat.log -subject ""SQL Server process not running"" -body ""SQL Server process not running""", 1, True

I did the same but starange error, Please look into this.

 
C:\Documents and Settings\Fareedm\Desktop>Blat -install 192.168.100.204 3 FROMM
25
SMTP server set to 192.168.100.204 on port 25 with user 3, retry FROMME25 time(
)
C:\Documents and Settings\Fareedm\Desktop>cscript.exe check.vbs
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Documents and Settings\Fareedm\Desktop\check.vbs(15, 2) (null): The system c
nnot find the file specified.

C:\Documents and Settings\Fareedm\Desktop>blat
Blat v1.8.2b: WinNT/95 console utility to mail a file via SMTP
by P.Mendes, M.Neal, G.Vollant, T. Charron
  http://www.interlog.com/~tcharron/blat.html
syntax:
  Blat <filename> -t <recipient> [optional switches (see below)]
  Blat -install <server addr> <sender's addr> [<try>[<port>[<profile>]]] [-q]
  Blat -profile [-delete | "<default>"] [profile1] [profileN] [-q]
  Blat -h [-q]
-install <server addr> <sender's addr> [<try n times> [<port> [<profile>]]]
     : set's SMTP server, sender, number of tries and port for profile
       (<try n times> and <port> may be replaced by '-').
<filename>     : file with the message body ('-' for console input, end with ^Z
-t <recipient> : recipient list (comma separated)
-s <subj>      : subject line
-f <sender>    : overrides the default sender address (must be known to server)
-i <addr>      : a 'From:' address, not necessarily known to the SMTP server.
-c <recipient> : carbon copy recipient list (comma separated)
-b <recipient> : blind carbon copy recipient list (comma separated)
-o <organization>: Organization field
-h             : displays this help.
-q             : supresses *all* output.
-noh           : prevent X-Mailer header from showing homepage of blat
-noh2          : prevent X-Mailer header entirely
-p <profile>   : send with SMTP server, user and port defined in <profile>.
-server <addr> : Specify SMTP server to be used. (optionally, addr:port)
-port <port>   : port to be used on the server, defaults to SMTP (25)
-hostname <hst>: select the hostname used to send the message
-mime          : MIME Quoted-Printable Content-Transfer-Encoding.
-uuencode      : Send (binary) file UUEncoded
-base64        : Send (binary) file using base64 (binary Mime)
-try <n times> : how many time blat should try to send. from '1' to 'INFINITE'
-attach <file> : attach binary file to message (may be repeated)
-attacht <file>: attach text file to message (may be repeated)
Note that if the '-i' option is used, <sender> is included in 'Reply-to:'
and 'Sender:' fields in the header of the message.
C:\Documents and Settings\Fareedm\Desktop>

C:\Documents and Settings\Fareedm\Desktop\check.vbs(15, 2) (null): The system c
nnot find the file specified.

Did you give the full path for blat ?

can you post the script here...