Oracle® ZFS Storage Appliance 管理指南,发行版 2013.1.5.0

退出打印视图

更新时间: 2016 年 2 月
 
 

使用 Children 函数

即使是在具有静态子代的上下文中,以编程方式迭代这些子代同样非常有用。这可以使用 children 函数实现,该函数返回静态子代数组。

  1. 例如,下面是迭代每个服务的脚本,输出服务的状态:
    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. 下面是运行该脚本的输出(假设将其保存到名为 "svcinfo.aksh" 的文件中):
    % ssh root@koi < space.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