Appendix K. Macros

This appendix describes the use of macros for building user templates and accounts. A description of macros for mailing from form letters is also included.

User Account Macros

You can use macros to help initialize the form fields when you create a User Account. You can enter these macros manually. Or you can have them fill (some of) the form fields automatically by first defining them in a New User Template and using that template when you create the user account.

The following types of fields accept macros in these two windows:

  • Login Name

  • Home dir.

  • Password

  • Mail Alias

For working examples, see “Macro Name”.

Format

A macro has the following format:

%<Modiiers><Macro Name>

Modifiers

<Modifiers> are optional (you can define them multiple times). You can use the <Modifiers> to specify only specific parts of the field, such as the first letter of the field, or to manipulate and convert the given input.

A modifier has the following format:

[<Converter><Range>]

where <Converter> is one or more of the following characters:

l  

- Convert the resulting string to lowercase

L 

- Same as `l'

u  

- Convert the resulting string to uppercase

U  

- Same as `u'

s  

- Do not include SPACEs

S  

- Same as `s'

_  

- Replace SPACEs with underscores (_)

and the <Range> applies to the complete string in the field (by default). Or you can apply a range to a specific word in the input string.

Consequently, a <Range> has the following format:

$<word number><Character Range>

where <word number> shows the word's sequence in the string (this is optional). The first word would be addressed as $1, the second word as $2, and so on. You can also use $0 to address the first word.

<Character Range> is a comma-separated list of character ranges in the form. If you specify a <word number>, you must first use a comma (`,') in the range list.

The character range itself has the following format:

<start char>-<end char>

where <start char> and <end char> are character numbers. You can omit one end of the range to signify the “start of string” and “end of string”, respectively. Ranges that go beyond the end of the string are truncated to match the string.

Macro Name

<Macro Name> is one of the following characters:

g 

- replace with the users' GID

u 

- replace with the user's UID

G 

- replace with the users' group name

U 

- replace with the user's login name (username)

R 

- replace with data from the user's Real Name field

O 

- replace with data from the user's Office field

T 

- replace with data from the user's Telephone field

Examples

These definitions make more sense when they are viewed as examples. Assume for the following example, the following data is true:

Real Name: 

Thomas Kraus

Login Name: 

tmk

UID: 

302

You could then define the following macros and see the following substitutions.

Field Name

Macro

Value

Home Dir

/home/%U

/home/tmk

Password

%U-%u

tmk-302

Mail Alias

%[u$1]R_%[u$2]R

THOMAS_KRAUS

Login Name

%[l$1,1][l$2,-6]R

tkraus

Some explanations:

/home/%U 

Create the directory /home/<login name>

%U-%u 

Get the User name and add the UID (separated by a dash)

%[u$1]R_%[u$2]R 


Get the first word of the user's real name and add the second word of the user's real name (separated by an underscore). Convert both strings to uppercase.

%[l$1,1][l$2,-6]R  


Take the first letter of the user's first name and the first six letters of the user's last name. Convert both strings to lowercase.

Form Letter Macros

You can also use macros to define various text strings in a form letter. You need to enter these macros manually in the appropriate form letter. The following table shows the name and the effective substitution for each of these macros.

Macro

Function

Effect

%D

System Date

The system date in the format of Sun Mar16 10:32:01 1996
will be substituted for the macro.

%G

Group Name

The User's Group Name will be substituted for the macro.

%g

Groupid

The User's GID will be substituted for the macro.

%H

Home Dir

The User's HOME directory will be substituted for the macro.

%O

Office

The User's Office location will be substituted for the macro.

%R

Real Name

The User's Real Name will be substituted for the macro.

%T

Telephone

The User's Telephone number will be substituted for the macro.

%U

User Name

The User's Login Name will be substituted for the macro.

%u

Userid

The User's UID will be substituted for the macro.

%X

Report

The report displayed in the window will be included in the letter.

%x

Sub Report

Only the selected lines of the report displayed in the window will be included in the letter.