VB scripts for windows file activities

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
Developer9
Premium Member
Premium Member
Posts: 187
Joined: Thu Apr 14, 2011 5:10 pm

VB scripts for windows file activities

Post by Developer9 »

Hi,

In our project ,We are using Execute Command Activity stage to call vb scripts (to perform various file movement activities like deletion,rename and append filename ) But Some times the scripts are running for ever .Unfortunately there isn't much logging available

I would like to know if there are any alternatives to using vb scripts OR develop more error handling ?

Thanks,
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Well... you can always go all old school and learn how to write DOS batch files as you certainly don't need VB just to do simple activities like that. Question to the home audience: does the 11.x release on Windows still allow the use of 'UNIX' scripts on the server?
-craig

"You can never have too many knives" -- Logan Nine Fingers
Developer9
Premium Member
Premium Member
Posts: 187
Joined: Thu Apr 14, 2011 5:10 pm

Post by Developer9 »

@chulett ,Thank you for the response .

The issue is happening randomly ..This morning job runs were successful but when I try to re-run now they are getting struck at point (file deletion script )..

No action there after:

Code: Select all

STATUS REPORT FOR JOB: jb_rename_datasets..Job status=1 (Finished OK)
SEQ_Load.JobControl (@rename_ds): Checkpointed run of job 'jb_rename_datasets'
The same jobs are running fine in Production (several times daily schedule)

We had to kill this struck Sequence job manually ..How can I get more details in the logs ?
Thanks
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Someone with VB skills would have to answer that, assuming you mean more details from the VB.

Typically, when I see file activities "get stuck" it usually means that the process has stopped to ask a question - generally some kind of "are you sure?" question - and it waits for a response. Since there's no-one to answer, it waits forever. Depending on the command, a "force" option is available or there's an unattended way to tell it "Y" if it asks. Hard to help more without knowing exactly what you are doing and how you are doing it...
-craig

"You can never have too many knives" -- Logan Nine Fingers
UCDI
Premium Member
Premium Member
Posts: 383
Joined: Mon Mar 21, 2016 2:00 pm

Post by UCDI »

I think a dos command is the way to go for sure. Vb just adds a layer of slowness to the task, if all you are doing are simple file operations. I seem to remember that you will want a text file with the letter Y in it, you can re-direct this into commands that expect the user to hit Y to confirm and don't have a force option (there are, or once were, a couple).

Still, if it is working and you want to go with what you have, post the code.

Yet another option is you could put the unix tools on your system (eg, cygwin) and call unix command line statements, which are a bit more flexible than the dos ones if you need more complex operations, and you can see more hits on working commands from a web search.
Developer9
Premium Member
Premium Member
Posts: 187
Joined: Thu Apr 14, 2011 5:10 pm

Post by Developer9 »

@chulett,UCDI ..Thank you for the input

This time different script having issue like above.I am using these vb scripts for basic file operations, renaming and deletion of data sets and text files .

One example here ,the script is replacing strings from filename.

Code: Select all

'rename filename which are ending with "_NextPrev" to "_Previous"

Dim control_dir,fso
Set fso = Wscript.Arguments
control_dir=fso.Item(0)
Call rename_files(control_dir)

	
Public Function rename_files(sSourceFolderPath)	
		Dim sNameDim , fsoDim , fol , ReturnValue
        ' create the filesystem objectSet 
        Set fso2 = CreateObject("Scripting.FileSystemObject")    
        ' get current folderSet
        Set fol = fso2.GetFolder(sSourceFolderPath)
        
      ' go thru each files in the folder
    For Each fil In fol.Files    
        ' check if the file name contains NextPrev   
        If InStr(1, fil.Name, "NextPrev") <> 0 Then       
        ' replace underscore with Previous       
        sName = Replace(fil.Name, "NextPrev", "Previous")       
         ' rename the file       
         fil.Name = sName   
 
         End If

     Next 

     For Each fil In fol.Files    
        
		' check if the file name contains NextPrev   
        If InStr(1, fil.Name, "NextPrev") <> 0 Then       
         ReturnValue = 1  
		   WScript.Quit(ReturnValue)
    Else
        ReturnValue = 0 
			WScript.Quit(ReturnValue)
 
        End If

     Next 
	 
      
 

End Function

Execute command options

Code: Select all

command : scriptsfolder\rename_NextPrev_Prev.vbs
Parameters: datafolder\ctl\
Trigger expressions : ren_nextprev_prev.$ReturnValue = '1' (abort)
                             ren_nextprev_prev.$ReturnValue = '0' (Success)
Here is the Director log entries from for successful run

Code: Select all

Sequence123..JobControl (@ren_nextprev_prev): Executed: scriptsfolder\rename_NextPrev_Prev.vbs datafolder\ctl\
Reply=0
Output from command ====>
Sequence123..JobControl (@ren_nextprev_prev): Checkpointed execution of command 'scriptsfolder\rename_NextPrev_Prev.vbs'
Sequence123 -> (jb_template):Job run requested ...
This Sequence job (with execute command) runs fine daily with no issues in production where as in lower environment It has an issue to proceed further in job flow after check pointed execution of command .It keeps on waiting and wait for ever .Unfortunately like other parallel job stages ,execute command stage does not provide much information to view from job log or I might have to do additional coding for more details on job log.

I have following questions :

How to get additional information from execute command stage in job log to debug this kind of issues ?
How to forcibly exit the command if it wait for certain time for command output status ?
How to debug from the datastage server level (if any) ?
Please let me know your suggestions.
UCDI
Premium Member
Premium Member
Posts: 383
Joined: Mon Mar 21, 2016 2:00 pm

Post by UCDI »

whatever is printed to the console is brought back by execute command BUT I don't know if that is only done at the end of execution or if it picks it up midstream.

Is there any reason you can't put the basic into a routine (which CAN write directly to the logs easily) and call that in a routine activity instead.
Developer9
Premium Member
Premium Member
Posts: 187
Joined: Thu Apr 14, 2011 5:10 pm

Post by Developer9 »

For this I need to look into basics for coding routine for this requirement from scratch .
UCDI
Premium Member
Premium Member
Posts: 383
Joined: Mon Mar 21, 2016 2:00 pm

Post by UCDI »

it should not be from scratch.
what you have should work with only minor adaptation, and once it works, adding the write to log messages isnt too bad (but if you need help, ask).

this link is a huge help:

https://www.ibm.com/support/knowledgece ... mming.html

Make note of the link to the "dsloginfo" function.
Post Reply