Using the Children Function

Even in a context with static children, it can be useful to iterate over those children programmatically. This can be done by using the children function, which returns an array of static children.

  1. For example, here is a script that iterates over every service, printing out the status of the service:
    configuration services
    script
           var svcs = children();
           for (var i = 0; i < svcs.length; ++i) {
                    run(svcs[i]);
                    try {
                            printf("%-10s %s\n", svcs[i], get('<status>'));
                    } catch (err) { }
                    run("done");
           }
  2. Here is the output of running the script, assuming it was saved to a file named svcinfo.aksh:
    $ ssh root@hostname < svcinfo.aksh
    Password: 
    cifs       disabled
    dns        online
    ftp        disabled
    http       disabled
    identity   online
    idmap      online
    ipmp       online
    iscsi      online
    ldap       disabled
    ndmp       online
    nfs        online
    nis        online
    ntp        online
    scrk       online
    sftp       disabled
    smtp       online
    snmp       disabled
    ssh        online
    tags       online
    vscan      disabled