動的な子が存在するコンテキストでは、これらの子をプログラムから繰り返し処理すると非常に有効です。これを行うには、動的な子の配列を返す list 関数を使用します。
script run('shares'); projects = list(); for (i = 0; i < projects.length; i++) { run('select ' + projects[i]); shares = list(); for (j = 0; j < shares.length; j++) { run('select ' + shares[j]); printf("%s/%s %1.64g %1.64g\n", projects[i], shares[j], get('space_data'), get('space_available')); run('cd ..'); } run('cd ..'); }
% ssh root@koi < space.aksh Password: admin/accounts 18432 266617007104 admin/exports 18432 266617007104 admin/primary 18432 266617007104 admin/traffic 18432 266617007104 admin/workflow 18432 266617007104 aleventhal/hw_eng 18432 266617007104 bcantrill/analytx 1073964032 266617007104 bgregg/dashbd 18432 266617007104 bgregg/filesys01 26112 107374156288 bpijewski/access_ctrl 18432 266617007104 ...
script run('shares'); projects = list(); printf('%-40s %-10s %-10s\n', 'SHARE', 'USED', 'AVAILABLE'); for (i = 0; i < projects.length; i++) { run('select ' + projects[i]); shares = list(); for (j = 0; j < shares.length; j++) { run('select ' + shares[j]); share = projects[i] + '/' + shares[j]; used = run('get space_data').split(/\s+/)[3]; avail = run('get space_available').split(/\s+/)[3]; printf('%-40s %-10s %-10s\n', share, used, avail); run('cd ..'); } run('cd ..'); }
% ssh root@koi < prettyspace.aksh Password: SHARE USED AVAILABLE admin/accounts 18K 248G admin/exports 18K 248G admin/primary 18K 248G admin/traffic 18K 248G admin/workflow 18K 248G aleventhal/hw_eng 18K 248G bcantrill/analytx 1.00G 248G bgregg/dashbd 18K 248G bgregg/filesys01 25.5K 100G bpijewski/access_ctrl 18K 248G ...
形式は、list ([depth, [filter]]) です。引数 depth は、1 つの数値で定義できます。depth の数値を大きくすると、より詳細な出力が返されます。引数 filter の形式は、{<prop1>:<val1>, <prop2>:<val2> ...} です。filter を指定する場合は、depth も指定する必要があります。
使用方法と入力の動作:
list() - ノード名のみを返します。
list(0) - ノードのプロパティーと子の名前のみ返します。
list(0, {kiosk_mode: true}) - kiosk_mode が true の場合のフィルタ済みリストと子の名前を返します。
list(1) - ノードのプロパティー、子の名前とプロパティー、孫の名前のみ返します。
list(1, {kiosk_mode: true}) - kiosk_mode が true の場合のフィルタ済みリストと depth=1 までの詳細を返します。
list(2) - ノードのプロパティー、子の名前とプロパティー、孫の list(0) 出力を返します。
list(2, {fullname:'Super*', kiosk_mode: true}) - fullname に Super を含み、kiosk_mode が true の場合のフィルタ済みリストと、depth=2 までの詳細を返します。
ラベル name はリスト項目 (すなわちノード) の名前を示します。ラベル properties はリスト項目のプロパティーを示します。ラベル children はリスト項目の静的な子を示します。ラベル list はリスト項目の動的な子を示します。
script ("." to run)> dump(list(2)); ("." to run)> . [{ name: 'restuser', properties: { kiosk_screen: 'status/dashboard', kiosk_mode: false, roles: ['basic'], require_annotation: false, initial_password: 'DummyPassword', fullname: 'REST User', logname: 'restuser' }, children: [{ name: 'preferences', properties: { advanced_analytics: false, session_timeout: 15, login_screen: 'status/dashboard', locale: 'C' } }, { name: 'exceptions', list: [{ name: 'auth-000', properties: { allow_configure: false, scope: 'alert' } }, { name: 'auth-001', properties: { allow_workgroup: false, allow_domain: false, name: '*', scope: 'ad' } }] }] }]