Monday, September 11, 2006

Ascential DataStage: Linux Sendmail and Notification Activity

To understand how to use the Notification Activity in a Linux environment, it is helpful that we review the basic of the Linux Sendmail command.

1. Lunix Sendmail Command

The sendmail package is normally located in /usr/sbin/. If you are not sure where it is located, you can use the which command to find out:



# which sendmail
/usr/sbin/sendmail

The syntax for sendmail is:

Sendmail [flags] [address ...]

There are many flags you can apply with sendmail. You can always find them from the man page. The address is the recipient’s address.

If you want to send a message from the Linux command line, you can just simply type:

Sendmail receipents-email-address
enter body of message
CTRL-D

Receipents-email address is the email address you want to the email to go to. For example, joe@domain.com. After you press enter, you can enter the email message. When you are done with your email message, press CTRL-D to send the message.

By sending the message from the commend line, the message will include your login id as in the From: line; moreover, the message is missing a useful TO: line and it does not give you the option to include a Subject line. To include the To: line and Subject line in your message, you need to create a txt file. Following is an example of the text file:

To: reciepient@domain.com
Subject: Email subject
From: sender@domain.com

message body here

To send the message, you can type:

#/usr/sbin/sendmail -t -i < mail_msg.txt

The –t option tells sendmail to read the email header information from the input file mail_msg.txt. The –i option is used to tells sendmail to ignore dots alone on lines by themselves in incoming messages. This should be set if you are reading data from a file.

2 The dssendmail_template.txt File

By default, DataStage place a file called dssendmail_template.txt in each project directory (folder). This file is used as a template to generate a script, which a name likes sendmail_loadjob56334_5532.sh in Linux or UNIX, to send message from the dat astage server. The default is set for using sendmail in UNIX.

#!/bin/sh
/usr/lib/sendmail -t <<////
From: %from%
To: %to%
Subject: %subject%
%body%
////

In runtime, the variables are substituted by the variables which are provided in the Notification Activities or the parameters passed to the DSSendMail routine. The dssendmail_template.txt has the detail explanations on how the tokens are recognized in the template as well as how to set up the template to using with window or NT system. DataStage Engine; actually, recognize two file names. The engine will first look for a file called "dssendmail.txt". If it dose not exist, it will use the "dssendmail_template.txt". This allows for local customization and prevents dssendmail.txt override by DataStage re-install. You can have a template file for each project. This allows you to have different Notification email formats for different projects. It is also possible to use different email packages, such as mail, to send mail. This is an example dssendmail.txt file:

#!/bin/sh
/usr/sbin/sendmail -t -i <<////
From: %from%
To: %to%
Subject: %subject%
%body%
////

3. Notification Activity

The fields in the Notifications page of the Notification Activity correspond to the tokens in the template file. If your particular template does not use a particular field, then setting it in the Notification page has no effect. For example, UNIX Systems generally require you to specify a Senders email address whereas Windows systems do not. So specifying this field may be mandatory in a UNIX system, but have no effect in a Windows system.

The Notification page contains:

• SMTP Mail server name. The name of the server or its IP address.
• Senders email address. Given in the form prodmonitor@domain.com.
• Recipients email address. The address the email is to be sent to, given in the form of admin@domain.com


• Email subject. The text to appear as the email subject.
For all the above, you can specify a parameter whose value will be specified at run time. Click the Browse button to open the External Parameter Helper, which shows you all parameters available at this point in the job sequence. Parameters entered in these fields need to be delimited with hashes (#). Parameters selected from the External Parameter Helper will automatically be enclosed in hash symbols.

• Attachments. Files to be sent with the email. Specify a path name, or a comma-separated list of pathnames (in the latter case this should be contained in single-quotes or double-quotes). You can also specify an expression that resolves to a pathname or commaseparated pathnames. The Arrow button offers you the choice of
browsing for a file or inserting a job parameter whose value will be supplied at run time. Again, parameters entered in these fields need to be delimited with hashes (#). Parameters selected from the External Parameter Helper will automatically be enclosed in hash symbols.

• Email body. The actual message to be sent. (Do not enclose the message in inverted commas unless you want them to be part of the message.)

• Include job status in email. Select this to include available job status information in the message.

• Do not checkpoint notification. Set this to specify that DataStage does not record checkpoint information for this particular notification operation. This means that, if a job later in the sequence fails, and the sequence is restarted, this notification operation will be reexecuted regardless of the fact that it was executed successfully before. This option is only visible if the sequence as a whole is checkpointed.


1 comment:

Anonymous said...
This comment has been removed by a blog administrator.