Friday, June 21, 2013

Command Task

The command will allow us to specify one or more shell commands to run during the workflow with the Command task.

For example:
We can specify shell commands in the Command task to delete reject files, copy a file, or archive target files.

There are two ways to use Command task:

1. Standalone Command task. We can use a Command task anywhere in the workflow or worklet to run shell commands.

2. Pre- and post-session shell command. We can call a Command task as the pre- or post-session shell command for a Session task. We can call them in COMPONENTS TAB of the session. We can run them in Pre-Session Command or Pre-Session Command or Post-Session Failure Command. By selecting the task “Type” and its value.


Note:
You can use any valid UNIX command or shell script for UNIX servers, or any valid DOS or batch file for Windows servers.

Example: To copy a ‘Test.txt’ file from one directory to another, you can use a shell command or windows command.

UNIX Syntax:
cp sales/sales_adj/Test.txt marketing/

Windows Syntax:
copy C:\sales\sales_adj/Test.txt D:\marketing\

Using Parameters and Variables
We can use parameters and variables in standalone Command tasks and pre- and post-session shell commands.

For Example: You might use a service process variable instead of hard-coding a directory name.

We can use the following parameters and variables in commands:
  • Standalone Command tasks. We can use service, service process, workflow, and worklet variables in standalone Command tasks. We cannot use session parameters, mapping parameters, or mapping variables in standalone Command tasks. The Integration Service does not expand these types of parameters and variables in standalone Command tasks.
  • Pre- and post-session shell commands. We can use any parameter or variable type that we define in the parameter file.
Creating a Sample Command Task:

Complete the following steps to create a Command task.

1. In the Workflow Designer or the Task Developer
Note: The Tasks created at 'Task Developer' are re-usable tasks.

2. Click Task --> Create. 
 
 3. Select Command Task for the task type to create:
 
 4. Enter a name for the Command task as 'cmd_copy_files'. Click Create. Then click Done.
 
 5. Double-click on the Command task in the workspace to open the Edit Tasks dialog box.
 
6. Go to the Commands tab, click the Add button to add a command. 
 
7. In the Name field, enter a name for the new command.
 
8. In the Command field, click the Edit button to open the Command Editor. 
 
9. Enter the command you want to run. Enter one command in the Command Editor.

You can use service, service process, workflow, and worklet variables in the command.

Example:

Windows Command:
copy $PMTargetFileDir\file\employee.txt $PMSourceFilesDir\file\employee.txt

Unix Command:
cp $PMTargetFileDir/file/employee.txt $PMSourceFilesDir/file/employee.txt

10. Click OK to close the Command Editor.
11. Repeat steps 4 to 9 to add more commands in the task.
12. Go to the Properties Tab:
a) Fail task if any command fails: If you select this option, the Integration Service stops running the commands and fails the Command task if any command fails. If you do not select this option, the Integration Service runs all the commands and treats the Command task as completed even if one of the command fails.
b) Recovery Strategy: Select either 'Fail task and continue workflow' or     'Restart task'
13. Click OK.

Note: If you want to create non-reusable command task then create it in workflow designer and follow the step 2 to step 13.

Now we have create re-usable command task and now we need to use this in session inside the workflow. (Open the workflow or worklet where you want to use this command task).

14. Select the session in the workspace, double click to edit and go to the components tab.

a) Select the task option where you want to use it 'Pre-Session Command' or 'Post-Session Success Command' or 'Post-Session Failure Command'.
 
b) Select Type 'Reusable' and click the Edit button to open the Command Editor. 
 
c) From Task Browser select the command 'cmd_copy_files', click 'Ok'
 
d) Click 'Apply' and 'Ok'.

Note:
1. If you specify non-reusable shell commands for a session, you can promote the non-reusable shell commands to a reusable Command task.
2. In Pre-Session Command the command task is use to copy the files from another location informatica server or archive the target file before it start session or rename the source/target file.
3. In Post-Session Success Command the command task is use to archive the source file after session succeeded or copy the target file to another location or rename the target/source file or trigger/stop/abort the another workflow or worklet using pmcmd command.
4. In Post-Session Failure Command the command task is use to archive the source file after session succeeded or copy the target file to another location or rename the target/source file or trigger/stop/abort the another workflow or worklet using pmcmd command.


9 comments:

  1. Very good and clear explanation.
    Thank you Gowtham

    ReplyDelete
  2. Yes clear and easy to uderstand

    ReplyDelete
  3. Really great... thanks a looot..

    ReplyDelete
  4. Excellent stuff. Thanks

    ReplyDelete
  5. appreciate your hard work. excellent

    ReplyDelete
  6. hi, Please let me know if can use # to comment out a command in the command task.

    ReplyDelete
  7. How to use bash shell script with several params?

    ReplyDelete