#!/usr/bin/perl use strict; use warnings; # Author: jhalbig@perforce.com # Date: Jan 9, 2026 # After several years of successful implementation my plan is to render this # ready for prime-time usage by cleaning up and fully documenting the settings # with an internal KB that will one day be presentable to a wider audience; for # now this will be useful for support engineers for cases where the server loads # don't appear to be utilizing all Linux OS hardware, networking resources in # particular. # # Usage: ./parse_sysctl.pl {-a} {/path to/}sysctl.out # # -a: # # Check rarely tweaked kernel settings. # # {/path to/}sysctl.out: # # The 'sysctl -a' output file to parse. # # Or change this sysctl_file value to a file containing "sysctl -a" output: my $sysctl_file = "sysctl.out"; # List of recommended kernel values: my $rec_k_vals = < $1, 'old_val' => "none", 'new_val' => $2}; $a++; } # Parse the sysctl output file to determine if there are any values that need to # be changed or added: open (SYSCTL, "< " . $sysctl_file) or die $usage_txt . "ERROR: Can't read file " . $sysctl_file .":\n" . $!; while () { chomp; s/\r$//; # strip a trailing carriage return left behind by Windows-style line endings foreach my $val (keys %k_vals) { if (/^.*?\Q$k_vals{$val}{'name'}\E\s+?=\s+?(.*)$/) { $k_vals{$val}{'old_val'} = $1; } } } close SYSCTL; ## Create the pretty table with comparison values print $txt_1; foreach my $val (sort keys %k_vals) { $k_vals{$val}{'old_val'} =~ s/\t/\x20/g; # normalize tabs to spaces next if $k_vals{$val}{'old_val'} eq "none"; # setting wasn't found in the sysctl output next if $k_vals{$val}{'old_val'} eq $k_vals{$val}{'new_val'}; # already at the recommended value print "\t" . $k_vals{$val}{'name'} . "\t\t" . $k_vals{$val}{'new_val'} . "\t" . "(" . $k_vals{$val}{'old_val'} . ")\n"; } ## Create the ready to paste OS commands to change those settings: print $txt_2; foreach my $val (sort keys %k_vals) { next if $k_vals{$val}{'old_val'} eq "none"; # setting wasn't found in the sysctl output next if $k_vals{$val}{'old_val'} eq $k_vals{$val}{'new_val'}; # already at the recommended value $q = ($k_vals{$val}{'new_val'} =~ m/\s/) ? "\"" : ""; print "\t" . $sysctl_cmd . " " . $k_vals{$val}{'name'} . "=" . $q . $k_vals{$val}{'new_val'} . $q . "\n"; } print $txt_3; print $txt_4; ## Create the ready to paste Perforce server commands: foreach my $val (keys %p4d_vals) { print "\t" . $p4_cmd . " " . $val . "=" . $p4d_vals{$val} . "\n"; } ## Print "p4 admin restart" command: print $txt_5; ## Closing text. print $txt_6; # WARNING: While this detects differences in values, the original values might # already have been tweaked! Remember to remove those lines that are already # at good values, taking care to remove the associated "sysctl -w" entry.