동적 자식 항목이 있는 컨텍스트에서는 이러한 자식 항목을 프로그래밍적으로 반복하면 매우 유용할 수 있습니다. 이렇게 하려면 동적 자식 항목 배열을 반환하는 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@hostname < 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@hostname < 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 인수는 숫자로 정의할 수 있습니다. depth 숫자가 클수록 더 많은 세부정보가 반환됩니다. filter 인수의 형식은 {<prop1>:<val1>, <prop2>:<val2> ...}입니다. filter가 지정된 경우 depth도 지정해야 합니다.
사용법 및 입력 동작:
list() - 노드 이름만 반환합니다.
list(0) - 노드의 등록 정보 및 하위 항목 이름만 반환합니다.
list(0, {kiosk_mode: true}) - kiosk_mode=true의 필터링된 목록을 하위 항목의 이름과 함께 반환합니다.
list(1) - 노드의 등록 정보, 하위 항목의 이름 및 등록 정보, 2차 하위 항목은 이름만 반환합니다.
list(1, {kiosk_mode: true}) - kiosk_mode=true의 필터링된 목록을 최대 depth=1까지의 세부정보와 함께 반환합니다.
list(2) - 노드의 등록 정보, 하위 항목의 이름 및 등록 정보, 2차 하위 항목의 list(0) 출력을 반환합니다.
list(2, {fullname:'Super*', kiosk_mode: true}) - Super를 포함하는 fullname, 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' } }] }] }]