| ## Doing More with dcecp The DCE control program accepts commands ranging from simple to complex, with more complex commands offering greater strength and versatility. Although simple commands are the easiest to compose, they are also limited, usually to performing one operation on a single object. So while it is always possible to enter simple commands, you'll probably find that at times, you want to repeat operations over several or even many objects, or to perform some operation only under certain conditions. For instance you might want to add some entry to a CDS directory only if some other specified entry already exists in CDS. The dcecp program makes this possible by utilizing Tcl's built-in commands that imitate elements commonly found in numerous programming and shell languages. The dcecp program contains many C-like constructs that control command execution. Some examples are if statements for conditional execution, looping commands such as while, for, and foreach used to repeat operations under various conditions, a case command for testing values against various patterns, and proc for writing your own customized commands. The dcecp program also includes other syntactic elements such as quotes (" "), braces ({ }), brackets ([ ]), and the backslash (\) character which it uses to group elements together and for controlling interpretation of special characters. Although many features are designed for use in scripts, you will probably find yourself using some constructs and elements (particularly quotes, braces, brackets, and backslashes) in interactive operations as well. You'll need to decide when it makes sense to perform operations interactively or to use a script. In general, complexity and potential for reuse can help you decide. Now let us look at a couple of simple examples that illustrate some DCE control program and Tcl basics. Some dcecp operations can be very straightforward like dcecp> account modify N_Long -expdate 1996-06-30 dcecp> This operation lets you change information in the DCE Security Service registry. Here, we're changing the account expiration date for the principal (N_Long) named in the command line. While it's relatively simple to execute this operation for one or two principals, it's more difficult to change the account expiration date for many principals. Imagine that your organization employs six temporary workers and the project they're associated with has been extended for three months. Rather than execute the account modify operation six times, you can use a dcecp foreach command to loop (repeat) an action for each item of a list: dcecp> foreach i {N_Long L_Jones P_Sawyer > D_Witt M_Dougherty S_Preska} { > account modify $i -expdate 1996-06-30 } dcecp> In the example, the foreach looping command has three arguments; a variable, a list, and the body. The variable i substitutes sequentially for each item in the list (N_Long, L_Jones, and so on). The foreach command executes the body (account modify $i -expdate 1996-06-30)) for each item in the list. The $i variable in the body takes on the value of each principal name in the list, in turn, until all items in the list have been used. See Loops Control Script Execution for more detailed information about looping commands. This example illustrates several other important syntax rules. The dcecp program uses braces ({ }) to determine where command arguments, such as the script body, begin and end. For example, the foreach command has three arguments: a variable name, a list, and a script body. Normally command arguments are separated by spaces. To prevent dcecp from incorrectly interpreting the spaces between list elements as argument separators, we use braces to enclose the list and disable special interpretation of the spaces. Thus all of the list elements appear as one argument. Similarly we use braces to enclose the individual elements in the script body. Braces also help dcecp determine whether a command is complete; incomplete commands will have more opening than closing braces. The lack of a closing brace at the end of the first line signals dcecp that more command input is coming so dcecp prompts with the secondary prompt (>). Similarly, the opening brace at the end of line 2 signals that you are still not finished entering the command. This lets you wrap lines without using a backslash (\) line wrap character. The dcecp program executes the command when you press Return after the closing brace at the end of line 3. Using the DCE Control Program Command Language contains more information about braces. Now, let us assume that instead of six temporary workers, your organization has fifty temporary workers (all in one group called temps) for whom you want to add three-month account extensions. We'll still use the foreach command but rather than write all fifty principals directly in the list, use the dcecp group list temps operation to generate a list for you. dcecp> foreach i [group list temps] { > account modify $i -expdate 1996-06-30 } dcecp> In this example, we've put the group list temps operation in square brackets ([ ]). Called command substitution, this technique replaces the command inside the square brackets with the results returned by that command. The results of the group list temps operation produces a valid Tcl list that might look like: dcecp> group list temps N_Long L_Jones P_Sawyer D_Witt M_Dougherty S_Preska . . . J_Jones Here, we have provided a high-level look at some practical uses of dcecp . Of course there's a lot we haven't seen, too. In Using the DCE Control Program Command Language we will look more closely at some of the dcecp operations that you're likely to use for DCE administration. Remember that dcecp is based on Tcl and Tcl has other commands and command variations we will not discuss. So be sure you have access to the standard Tcl publications for detailed information on all of the commands. ##