#!/usr/bin/env perl # zpoolStats - Display ZFS pool status and capacity statistics # # PURPOSE: # Reports comprehensive status information for all ZFS pools on the system, # including capacity, fragmentation, and health status. Essential for monitoring # pool health during sneakernet operations. # # USAGE: # Standalone: ./zpoolStats # From sneakernet: Executed automatically during cleanup phase # From Perl script: my ($results, $errors) = eval { do './zpoolStats' }; # # EXECUTION CONTEXT: # When executed by sneakernet on the target server: # - Script is read from transport drive, decrypted, and executed via eval() # - Results returned as tuple (output, error_messages) for logging # - When run standalone, prints results to STDOUT # # BEHAVIOR: # 1. Executes 'zpool list' with comprehensive output columns # 2. Shows: pool name, size, allocated space, free space, fragmentation, capacity, health # 3. Returns formatted output with any error messages # # OUTPUT FORMAT: # NAME SIZE ALLOC FREE FRAG CAP HEALTH # backup 10T 4.5T 5.5T 12% 45% ONLINE # storage 20T 15T 5T 8% 75% ONLINE # # RETURN VALUE: # When called from another script: ($results, $errors) # - $results: String containing zpool list output # - $errors: String containing error messages (empty if none) use strict; use warnings; # Get zpool list output my $zpool_cmd = 'zpool list -o name,size,alloc,free,frag,cap,health'; my @results = `$zpool_cmd 2>&1`; chomp @results; my @errors; # Check if command executed successfully if ($? != 0) { push @errors, "Error executing zpool list: $!"; } # Return or print results depending on context if (caller()) { # called from another script return ( join( "\n", @results ) . "\n", @errors ? join("\n", @errors) : "" ); } else { # run standalone print "Results Summary:\n"; print join( "\n", @results ) . "\n"; if (@errors) { print "\n=== CLEANUP SCRIPT ERRORS ===\n"; print join("\n", @errors) . "\n"; } } # End of script