#!/usr/bin/env perl # transportStats - Display disk usage statistics for transport drives # # PURPOSE: # Reports disk space usage for all filesystems mounted under /mnt, typically # used to monitor transport drives and report disks during sneakernet operations. # # USAGE: # Standalone: ./transportStats # From sneakernet: Executed automatically during cleanup phase # From Perl script: my ($results, $errors) = eval { do './transportStats' }; # # 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 'df -h' to get human-readable disk usage statistics # 2. Filters output to show only mounts under /mnt/ (where transport drives are mounted) # 3. Includes df header line for readability # 4. Returns formatted output with any error messages # # OUTPUT FORMAT: # Filesystem Size Used Avail Capacity Mounted on # /dev/gpt/data1 100G 45G 55G 45% /mnt/transport # /dev/gpt/data2 50G 20G 30G 40% /mnt/reports # # RETURN VALUE: # When called from another script: ($results, $errors) # - $results: String containing df output # - $errors: String containing error messages (empty if none) use strict; use warnings; my $caller = caller(); # Check if called from another script and, if not, prints updates to STDOUT # if we are being called from sneakernet, get verbosity level, otherwise just set to 5 my $verbosityLevel = ($caller && defined $ZFS_Utils::verboseLoggingLevel) ? $ZFS_Utils::verboseLoggingLevel : 5; # Get disk stats on anything mounted under /mnt # This assumes that transport disks are mounted under /mnt/ # will also get the reports disk if mounted there my $cmd = "df -h | grep -E '(^Filesystem)|(/mnt/)'"; my @results = `$cmd 2>&1`; chomp @results; my @errors; # Check if command executed successfully if ($? != 0) { push @errors, "Error executing df command: $!"; } # 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