At the recommendation of another user I am posting my scripting issue here..
I've created a vbscript monitor template that executes a sqlplus command on a remote windows server.
Running the vbs script locally, with modifications for local paths, works just fine.
Running the vbs script locally, with UNC paths, i.e. how it would run from the poller, works just fine as well.
But when executed from the SW poller, it seems as though there are issues.
I used WshShell.exec and it didnt seem like it was running at all, I changed that to WshShell.Run and I get "Sqlplus has stopped responding. Close program"
Is there something I'm missing with the way SW handles vbscripts?
I've included the vbs script below
.
Summary : Given the server name and oracle instance name.
Determine temp directory, determine server name, create a .sql command file on remote server with spool option. Execute the sqlplus command.
Open spooled file. and this is where it fails. So it creates the .sql file just fine on remote system, but i dont think its executing the sqlplus command.
Troubleshooting
I've tried turning off spool and using redirect to a file option as a part of the sqlcmd variable and the wshshell.exec parameters, neither of which work from SW, but all work locally.
I've also tried setting up an ODBC for Oracle connection without success.
I've tried escaping various characters in the sqlcmd
I've tried changing around sqlplus command
I've tried using the pipe symbol in the command
I've tried utilizing wshremote functions of vbscript without success. (creating script on poller and using wshremote to push to remote server and executing there)
I've tried capturing stderr and stdout from the vbscript, but they are always null.
I've opened a ticket with SW, but they referred me to the powershell doco and said they cant help with scripts, but I was really just asking how SW handles vbscript.
Permissions for the template credentials are domain and have access to the servers.
When I manually create the output file, the script executes as expected calculating free space and etc.
I changed from WshShell.exec to WshShell.Run
i implemented WshShell.Remote with an error stating "unable to create ActiveX object"
Any help is greatly appreciated.
Parameters : \\${IP}\C$\Temp DD21
Option Explicit
Dim LOGIN, DBName, SQLSelect, TmpDir, TmpDirSet, ArchiveDrive, EndofServer, ServerName, SQLDir
Dim WshShell, oExec, SQLOutput, fso, objfile, Disk, DiskFree, DiskTotal, DiskPercent
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = Wscript.CreateObject("WScript.Shell")
TmpDirSet = False
EndofServer = instr(3,Wscript.Arguments(0),"\",0)
ServerName = mid(Wscript.Arguments(0),1,EndofServer)
'---------------------------
'10
'-- Determine Temp directory
'---------------------------
if fso.folderexists(ServerName & "C$\Temp") then
SQLDir = "C:\Temp"
TmpDir = ServerName & "C$\Temp"
TmpDirSet = True
end if
if fso.folderexists(ServerName & "C$\Windows\Temp") and TmpDirSet = False then
SQLDir = "C:\Windows\Temp"
'20
TmpDir = ServerName & "C$\windows\Temp"
TmpDirSet = True
end if
if fso.folderexists(ServerName & "C$\WinNT\Temp") and TmpDirSet = False then
SQLDir = "C:\WinNT\Temp"
TmpDir = ServerName & "C$\WinNT\Temp"
TmpDirSet = True
end if
If TmpDirSet = False then
'30
WScript.Echo "Message: Unable to determine temp directory"
WScript.Echo "Statistic: 0"
Wscript.Quit(0)
end if
'-----------------------------------
'-- Setup Connection Info for Oracle
'-----------------------------------
LOGIN="oracleuserid/oracleuserpassword"
DBName=Wscript.Arguments(1)
'40
'----------------------------------
'-- Create Tempory SQL command file
'----------------------------------
Set objFile = fso.CreateTextFile(TmpDir & "\s_" & DBNAME & ".sql", true)
objFile.writeline("select value from v$parameter where name = 'log_archive_dest' and value is not null")
objFile.writeline("union all")
objFile.writeline("select value from v$parameter where name = 'log_archive_dest_1' and value is not null")
objFile.writeline("union all")
objFile.writeline("select value from v$parameter where name = 'log_archive_dest_2' and value is not null;")
'50
objFile.writeline("quit;")
objFile.Close
'----------------------------
'-- Execute SQLPlus Statement
'----------------------------
dim sqlcmd
wscript.sleep(2500)
sqlcmd = "runas /username:domain\username " & """cmd /c " & ServerName & "C$\oracle\ora81\bin\sqlplus.exe -s " & LOGIN & "@" & DBName & " < " & TmpDir & "\s_" & DBName & ".sql > " & TmpDir & "\sqloutput.log"""
oExec = WshShell.run(sqlcmd,0,TRUE)
'60
Wscript.Sleep 100
wshShell.AppActivate "Runas"
Wscript.Sleep 300
wshShell.SendKeys "domainaccountpassword"
Wscript.Sleep 100
wshShell.SendKeys "~"
wscript.sleep(10000)
'-------------------
'--Retrieve location
'70
'-------------------
Set objFile = fso.OpenTextFile(TmpDir & "\sqloutput.log", 1)
Do While objFile.AtEndOfStream = False
SQLOutput = objfile.readline()
if Instr(SQLOutput,":\") > 0 then
ArchiveDrive = mid(SQLOutPut,1,1)
Exit Do
end if
Loop
'80
objFile.Close
set Disk = fso.GetDrive(ServerName & ArchiveDrive & "$")
DiskTotal = Disk.TotalSize
DiskFree = Disk.FreeSpace
DiskPercent = (100 - ((DiskFree/DiskTotal)*100))
Wscript.echo "Statistic : " & FormatNumber(DiskPercent,2)
Wscript.echo "Message : " & SQLOutput
'----------------------------------
'-- Delete Tempory SQl command file
'90
'----------------------------------
fso.DeleteFile(TmpDir & "\s_" & DBNAME & ".sql")
fso.deleteFile(TmpDir & "sqloutput.log")