Event not running External process (.vbs) properly

General help on how to use Cerberus. Questions on how a particular feature works, how to use feature x with feature y... Please read the "How to use this forum" article before posting.
Post Reply
Ralvin
Posts: 1
Joined: Wed Jan 06, 2016 12:54 pm

Event not running External process (.vbs) properly

Post by Ralvin » Wed Jan 06, 2016 1:42 pm

Good afternoon Cerberus,

I am having several problems trying to use events to call a newly written vbs script.

What we are trying to accomplish: When a file is dropped on a Cerberus home directory with an {{LFP}} containing (in this case) "bentest" then cerberus should call the vbs script to run which does the following functions
1) SFTP the file using PSCP.exe to our interface server
2) Archive the file on our Cerberus server under C:\NAP_HL7_BK\{{U}}
3) Log the event within a custom txt within C:\NAP_HL7_BK\{{U}}

Currently we are moving the files to our interface server with a file copy operation to our interface servers Samba share using the Cerberus Event Manager. The purpose of the new script is to switch over to using SFTP because Samba is no longer being supported.

We have two Cerberus servers, one as our production that is running version 5.0.8.0. And another that is our upgrade environment on the latest version 8.0.0.4. We intend on migrating to the new server but that is another story.

Problem 1: On the older version of Cerberus (5.0.8.0) the script is transferring files just fine, however Cerberus is not supplying the VBS script with filenames that include a "^" (aka upper carrot symbol). We have worked with our vendors and they have assured us that the upper carrot symbol on their filenames cannot be changed.

Filename Example:
20160106_11060433_ADT^A08.hl7 becomes 20160106_11060433_ADTA08.hl7 when Cerberus reads the {{LFP}}
Because of this problem we decided to investigate the new version of Cerberus to see if it handles upper carrots better.

Unfortunately that caused more problems:

Problem 2: On the new version of Cerberus (8.0.0.4) The .VBS script is kicked off by the Event Manager properly (Found by the creation of my log file that is done prior to the PSCP step). however when it comes to use PSCP to transfer the file via SFTP the script stops dead. But when I run the script via command line the script runs fine.

Log File when I run the script manually:

Code: Select all

Path provided by Cerberus: C:\bentest\readme99.txt
User provided by Cerberus: bentest
SFTP Command: C:\Outgoing_SFTP_Transfers\pscp.exe -sftp -i C:\Outgoing_SFTP_Transfers\PrivateKey.ppk
Archive Path: C:\NAP_HL7_BK\bentest\
Finished attempting writing to INTPROD
Log File when Cerberus calls the script:

Code: Select all

Path provided by Cerberus: C:\bentest\readme99.txt
User provided by Cerberus: bentest
SFTP Command: C:\Outgoing_SFTP_Transfers\pscp.exe -sftp -i C:\Outgoing_SFTP_Transfers\PrivateKey.ppk
Archive Path: C:\NAP_HL7_BK\bentest\
Screenshot of Event Manager on the new server calling my VBS script

Below is my complete code for my vbs script I am calling.
Again, this script runs fine when I call the script through cmd.
**I have adjusted and renamed some of the code, servers, folders to protect identities**

Code: Select all


Set shell = WScript.CreateObject( "WScript.Shell" )
Set fso = CreateObject("Scripting.FileSystemObject")

Dim fso, Shell, strPath, strUser, strArchivePath, strSFTPCMD, strError, strReturn, strTimestamp, filesys, filetxt

strError = False
strTimestamp = now
strTimestamp = Replace(strTimestamp,"/","")
strTimestamp = Replace(strTimestamp,":","")
strTimestamp = Replace(strTimestamp,"-","")
strTimestamp = Replace(strTimestamp," ","")

Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set filesys = CreateObject("Scripting.FileSystemObject")

'set variables for {{LFP}} and {{U}} in Cerberus
strPath = WScript.Arguments.Item(0)
strUser = WScript.Arguments.Item(1)

'Set strSFTPCMD to run pscp command using private key for INTPROD and INTTEST
strSFTPCMD = "C:\Outgoing_SFTP_Transfers\pscp.exe -sftp -i C:\Outgoing_SFTP_Transfers\PrivateKey.ppk "

'Set strArchivePath to NAP archive directory for file transfers
strArchivePath = "C:\NAP_HL7_BK\" & strUser & "\"

'''''''''''''''''''''''''''''
'Write to logfile
outFile = strArchivePath & "LastOrderTransferLog1.txt"
Set objFile = fso.CreateTextFile(outFile,True)
objFile.Write "Path provided by Cerberus: " & strPath & vbCrLf & "User provided by Cerberus: " & strUser & vbCrLf & "SFTP Command: " & strSFTPCMD & vbCrLf & "Archive Path: " & strArchivePath & vbCrLf
objFile.Close

'''''''''''''''''''''''''''''''

'****** Transfer ******
strReturn = shell.run ( strSFTPCMD & strPath & " USER@INTPROD:incoming_nap",0,True)
Set filetxt = filesys.OpenTextFile ( outFile, ForAppending, True)
if strReturn <> 0 then
strError = True
filetxt.WriteLine ( "Error writing to INTPROD" & vbCrLf)
filetxt.Close
end if
filetxt.WriteLine ( "Finished attemping writing to INTPROD" & vbCrLf)
filetxt.Close

'Create Directory in archive folder
'********************
'Need to add if then statement to see if folder already exists
'********************
if not fso.FolderExists (strArchivePath) then
fso.CreateFolder strArchivePath
end if

'ERROR CHECKING, appends the word "ERROR" at the end of the filename if there was a detected error
if strError = True then
strPathMod = strPath & ".ERROR." & strTimestamp
else
strPathMod = strPath & "." & strTimestamp
end if

fso.MoveFile strPath, strPathMod

'Move order downloaded to C:\NAP_HL7_BK\{{U}}
fso.MoveFile strPathMod, strArchivePath
Not sure of the steps I needed to take to enter a support ticket so I will be entering one that references this forum post.

Any help is greatly appreciated.

Post Reply