scripts in vbscript ??
Moderators: Developers, Moderators
scripts in vbscript ??
Has anyone tried to use vbscript instead of Perl ?
If so how did you manage to do the 'last' print statement to 'transfer' the data into cacti ?
If so how did you manage to do the 'last' print statement to 'transfer' the data into cacti ?
You need to use WSH in conjunction with VBS. To have a console output you need to run your VB scripts with cscript.exe (not wscript.exe which is used by default). The following link will help you:
http://www.devguru.com/Technologies/wsh ... intro.html
- bulek
http://www.devguru.com/Technologies/wsh ... intro.html
- bulek
Let's make a simple test - running vbscript from php:
Some more examples how to interact with stdin/stdout with VBS:
http://msdn.microsoft.com/library/defau ... ations.asp
- bulek
Seems to be workingC:\>type test.vbs
WScript.StdOut.Write("512")
C:\>type test.php
<?
$result = `cscript c:/test.vbs //nologo`;
echo "Result is " . $result . "\n";
?>
C:\>php -q test.php
Result is 512
C:\>
Some more examples how to interact with stdin/stdout with VBS:
http://msdn.microsoft.com/library/defau ... ations.asp
- bulek
Bulek,
Perhaps I was unclear but I want to run vbs scripts instead of perl scripts to 'gather' the data.
So instead of
perl <path_to_cati>/scripts/ping.vbs < ip >
I want to use
cscript //nologo <path_to_cacti>/scripts/ping.vbs < ip >
This is what is giving the errors, running the script itself in a DOS box works fine !
-b
Perhaps I was unclear but I want to run vbs scripts instead of perl scripts to 'gather' the data.
So instead of
perl <path_to_cati>/scripts/ping.vbs < ip >
I want to use
cscript //nologo <path_to_cacti>/scripts/ping.vbs < ip >
This is what is giving the errors, running the script itself in a DOS box works fine !
-b
I understood you correctly. My example was simplified process of cacti gathering data. Cacti uses cmd.php to run all data input scripts with line:
$out_data_array = ParseDelimitedLine(`$str`,$delimeter);
$str variable contains your script name with arguments. In case of perl it would be 'perl somescript.pl arg1 arg2'. In case of vbscript it would be 'cscript somescript.vbs //nologo arg1 arg2'.
Sumarizing my example showed that test.php (which is used in place of cmd.php) was able to run vbscript test.vbs, fetch script's output and store it in a variable.
Maybe add some debug info in cmd.php. Check if <path_to_cacti> is resolved to real path. Check cscript syntax (//nologo should be between script name and its arguments). Check string returned before ParseDelimitedLine function is called.
BTW, It's interesting idea to use VBS to make data input scripts. Why I didn't think about this before you?
- bulek
$out_data_array = ParseDelimitedLine(`$str`,$delimeter);
$str variable contains your script name with arguments. In case of perl it would be 'perl somescript.pl arg1 arg2'. In case of vbscript it would be 'cscript somescript.vbs //nologo arg1 arg2'.
Sumarizing my example showed that test.php (which is used in place of cmd.php) was able to run vbscript test.vbs, fetch script's output and store it in a variable.
Maybe add some debug info in cmd.php. Check if <path_to_cacti> is resolved to real path. Check cscript syntax (//nologo should be between script name and its arguments). Check string returned before ParseDelimitedLine function is called.
BTW, It's interesting idea to use VBS to make data input scripts. Why I didn't think about this before you?
- bulek
Ok,
Here is my version of ping.vbs :
Dim oArgs, Answer, fso
Set oArgs = WScript.Arguments
If oArgs.Count <> 1 Then Wscript.Quit(0)
Set MyShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Const TempFile = "./ping.txt"
Program = "%comspec% /c ping.exe -n 1 " & oArgs(0) & " >" & TempFile
Return = MyShell.Run(Program,0,True)
Set MyFile = fso.OpenTextFile(TempFile)
Answer = MyFile.ReadAll
MyFile.Close()
'Set MyFile = fso.GetFile(TempFile)
'MyFile.Delete
If InStr(Answer,"ytes=") Then
p= InStr(Answer,"Average")
Wscript.StdOut.Write Val(Trim(Mid(Answer,p+10,10)))
Else
Wscript.StdOut.Write "0"
End If
Wscript.Quit(0)
function Val(vValue)
Dim lCount
Dim lResult
Dim strResult
if len(vValue) = 0 Then
lResult = 0
Else
if isnumeric(vValue) Then
lResult = cdbl(vValue)
Else
lCount = 1
Do until (isnumeric(mid(vValue,lCount,1))=false) or (lCount > len(vValue))
strResult = strResult & mid(vValue, lCount, 1)
lCount = lCount + 1
Loop
if len(strResult) = 0 Then
lResult = 0
Else
lResult = cdbl(strResult)
End if
End if
End if
Val = lResult
End function
Perhaps it can be shorter, but it is faster then the perl equivalent !
At least on my machine (P266).
-b
Here is my version of ping.vbs :
Dim oArgs, Answer, fso
Set oArgs = WScript.Arguments
If oArgs.Count <> 1 Then Wscript.Quit(0)
Set MyShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Const TempFile = "./ping.txt"
Program = "%comspec% /c ping.exe -n 1 " & oArgs(0) & " >" & TempFile
Return = MyShell.Run(Program,0,True)
Set MyFile = fso.OpenTextFile(TempFile)
Answer = MyFile.ReadAll
MyFile.Close()
'Set MyFile = fso.GetFile(TempFile)
'MyFile.Delete
If InStr(Answer,"ytes=") Then
p= InStr(Answer,"Average")
Wscript.StdOut.Write Val(Trim(Mid(Answer,p+10,10)))
Else
Wscript.StdOut.Write "0"
End If
Wscript.Quit(0)
function Val(vValue)
Dim lCount
Dim lResult
Dim strResult
if len(vValue) = 0 Then
lResult = 0
Else
if isnumeric(vValue) Then
lResult = cdbl(vValue)
Else
lCount = 1
Do until (isnumeric(mid(vValue,lCount,1))=false) or (lCount > len(vValue))
strResult = strResult & mid(vValue, lCount, 1)
lCount = lCount + 1
Loop
if len(strResult) = 0 Then
lResult = 0
Else
lResult = cdbl(strResult)
End if
End if
End if
Val = lResult
End function
Perhaps it can be shorter, but it is faster then the perl equivalent !
At least on my machine (P266).
-b
Who is online
Users browsing this forum: No registered users and 2 guests