forked from ryran/xsos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxsos
executable file
·4033 lines (3499 loc) · 166 KB
/
xsos
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# xsos v0.7.33 last mod 2024-06-25
# Latest version at <http://github.com/ryran/xsos>
# RPM packages available at <http://people.redhat.com/rsawhill/rpms>
# Copyright 2012-2018 Ryan Sawhill Aroha <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License <gnu.org/licenses/gpl.html> for more details.
#-------------------------------------------------------------------------------
# See https://github.com/ryran/xsos/issues/208
export LC_ALL=en_US.UTF-8
# Get version from line #2
version=$(sed '2q;d' $0)
# Colors and colors and colors oh my (but only for bash v4)
if [[ $BASH_VERSINFO -ge 4 ]]; then
declare -A c
c[reset]='\033[0;0m' c[BOLD]='\033[0;0m\033[1;1m'
c[dgrey]='\033[0;30m' c[DGREY]='\033[1;30m' c[bg_DGREY]='\033[40m'
c[red]='\033[0;31m' c[RED]='\033[1;31m' c[bg_RED]='\033[41m'
c[green]='\033[0;32m' c[GREEN]='\033[1;32m' c[bg_GREEN]='\033[42m'
c[orange]='\033[0;33m' c[ORANGE]='\033[1;33m' c[bg_ORANGE]='\033[43m'
c[blue]='\033[0;34m' c[BLUE]='\033[1;34m' c[bg_BLUE]='\033[44m'
c[purple]='\033[0;35m' c[PURPLE]='\033[1;35m' c[bg_PURPLE]='\033[45m'
c[cyan]='\033[0;36m' c[CYAN]='\033[1;36m' c[bg_CYAN]='\033[46m'
c[lgrey]='\033[0;37m' c[LGREY]='\033[1;37m' c[bg_LGREY]='\033[47m'
fi
# ==============================================================================
# ENVIRONMENT VARIABLES -- Modify these by setting them in your shell
# environment, e.g. ~/.bash_profile or /etc/profile.d/xsos.sh
# COLORS
# The following configure defaults for various colors to enhance output
# XSOS_COLORS (bool: y/n)
# Controls whether color is enabled or disabled by default
# Can also be controlled by cmdline arg
: ${XSOS_COLORS:="y"}
# XSOS_COLOR_RESET -- color to reset terminal to after using other colors
: ${XSOS_COLOR_RESET:="reset"}
# XSOS_COLOR_H1 -- color for content modules' primary header
: ${XSOS_COLOR_H1:="RED"}
# XSOS_COLOR_H2 -- color for content modules' secondary header
: ${XSOS_COLOR_H2:="PURPLE"}
# XSOS_COLOR_H3 -- color for content modules' tertiary header
: ${XSOS_COLOR_H3:="BLUE"}
# XSOS_COLOR_H4 -- color used only for SYSCTL() module
: ${XSOS_COLOR_H4:="reset"}
# XSOS_COLOR_IMPORTANT -- color for drawing attention to important data
: ${XSOS_COLOR_IMPORTANT:="BOLD"}
# XSOS_COLOR_WARN1 -- color for level-1 warnings
: ${XSOS_COLOR_WARN1:="orange"}
# XSOS_COLOR_WARN2 -- color for level-2 warnings
: ${XSOS_COLOR_WARN2:="ORANGE"}
# XSOS_COLOR_MEMGRAPH_MEMUSED -- color for MemUsed in MEMINFO() graph
: ${XSOS_COLOR_MEMGRAPH_MEMUSED:="green"}
# XSOS_COLOR_MEMGRAPH_HUGEPAGES -- color for HugePages in MEMINFO() graph
: ${XSOS_COLOR_MEMGRAPH_HUGEPAGES:="cyan"}
# XSOS_COLOR_MEMGRAPH_BUFFERS -- color for Buffers in MEMINFO() graph
: ${XSOS_COLOR_MEMGRAPH_BUFFERS:="purple"}
# XSOS_COLOR_MEMGRAPH_CACHED -- color for Cached in MEMINFO() graph
: ${XSOS_COLOR_MEMGRAPH_CACHED:="blue"}
# XSOS_COLOR_MEMGRAPH_DIRTY -- color for Dirty in MEMINFO() graph
: ${XSOS_COLOR_MEMGRAPH_DIRTY:="red"}
# XSOS_COLOR_IFUP -- color for ethtool InterFace "up"
: ${XSOS_COLOR_IFUP:="green"}
# XSOS_COLOR_IFDOWN -- color for ethtool InterFace "down"
: ${XSOS_COLOR_IFDOWN:="lgrey"}
# INDENTATION
# The following variables are not used universally and that might not change
# XSOS_INDENT_H1 -- 1st level of indentation
: ${XSOS_INDENT_H1:=" "}
# XSOS_INDENT_H2 -- 2nd level of indentation
: ${XSOS_INDENT_H2:=" "}
# XSOS_INDENT_H3 -- 3rd level of indentation
: ${XSOS_INDENT_H3:=" "}
# XSOS_FOLD_WIDTH (w, 0, or positive number)
# Some content modules print line of unpredictable length
# This setting controls the wrapping width for commands that use it
# Changing to w causes width of terminal to be used
# Changing to 0 causes 99999 to be used
: ${XSOS_FOLD_WIDTH:="w"}
# XSOS_HEADING_SEPARATOR (str)
# Acts as a separator between content modules
# Should include at least 1 trailing new-line
: ${XSOS_HEADING_SEPARATOR:="\n"}
# XSOS_ALL_VIEW (str of variables, space-separated)
# Controls what content modules to run when -a/--all switch is used
: ${XSOS_ALL_VIEW:="bios os kdump cpu intrupt mem disks mpath lspci ethtool softirq bonding ip netdev sysctl ps ss firewall"}
# XSOS_DEFAULT_VIEW (str of variables, space-separated)
# Controls default content modules, i.e. what to run when none are specififed
: ${XSOS_DEFAULT_VIEW:="os"}
# XSOS_PS_THREADS (bool: y/n)
# Controls whether PSCHECK() function parses `ps aux` or `ps auxm` output
: ${XSOS_PS_THREADS:="n"}
# XSOS_PS_LEVEL (int: 0-4)
# Controls verbosity level (4 being highest) in PSCHECK() function
: ${XSOS_PS_LEVEL:="1"}
# XSOS_MULTIPATH_QUERY (string: arbitrary regex)
# Only a tenuous case can be made for statically setting this
# It's used by the MULTIPATH() function to restrict display to a particular mpath device
# Traditionally controled by -q/--wwid option
: ${XSOS_MULTIPATH_QUERY:=""}
# XSOS_MEM_UNIT (str: b, k, m, g, t)
# Sets unit used by MEMINFO() function for printing
# Can also be controlled by cmdline opt -u/--unit
: ${XSOS_MEM_UNIT:="g"}
# XSOS_NET_UNIT (str: b, k, m, g, t)
# Sets unit used by NETDEV() function for printing Rx & Tx Bytes
# Can also be controlled by cmdline opt -u/--unit
: ${XSOS_NET_UNIT:="m"}
# XSOS_PS_UNIT (str: k, m, g)
# Sets unit used by PSCHECK() function for printing VSZ & RSS
# Not affected by cmdline opt -u/--unit option
: ${XSOS_PS_UNIT:="m"}
# XSOS_OUTPUT_HANDLER (str: application name)
# Sets name of application to handle output
: ${XSOS_OUTPUT_HANDLER:="cat"}
# XSOS_OS_RHT_CENTRIC (bool: y/n)
# Configures whether OSINFO() focuses on Red Hat support issues
: ${XSOS_OS_RHT_CENTRIC:="n"}
# XSOS_IP_VERSION (int: 4/6)
# Configures whether IPADDR() shows ipv4 or ipv6 addresses
: ${XSOS_IP_VERSION:="4"}
# XSOS_SCRUB_IP_HN (bool: y/n)
# Configures whether IP addrs & hostnames should be removed from output
: ${XSOS_SCRUB_IP_HN:="n"}
# XSOS_SCRUB_MACADDR (bool: y/n)
# Configures whether HW MAC addresses should be removed from output
: ${XSOS_SCRUB_MACADDR:="n"}
# XSOS_SCRUB_SERIAL (bool: y/n)
# Configures whether serial numbers should be removed from output
: ${XSOS_SCRUB_SERIAL:="n"}
# XSOS_SCRUB_PROXYUSERPASS (bool: y/n)
# Configures whether RHN/RHSM proxy user/pass should be removed from output
: ${XSOS_SCRUB_PROXYUSERPASS:="n"}
# XSOS_ETHTOOL_ERR_REGEX (str: awk-syntax regular expression)
# Configures what ETHTOOL() uses to generate the data under the "Interface Errors" heading
: ${XSOS_ETHTOOL_ERR_REGEX:='/Missing ethtool_-S file|(drop|disc|err|fifo|buf|fail|miss|OOB|fcs|full|frags|hdr|tso|pause|lost).*: [^0]/ && !/(fdir_|veb\.)/'}
# XSOS_LSPCI_NET_REGEX (str: regular expression)
# Configures what LSPCI() uses to search for peripherals under the "Net" heading
: ${XSOS_LSPCI_NET_REGEX:="(Ethernet controller|Network controller|InfiniBand)( \[[0-9]{4}\])?:"}
# XSOS_LSPCI_STORAGE_REGEX (str: regular expression)
# Configures what LSPCI() uses to search for peripherals under the "Storage" heading
: ${XSOS_LSPCI_STORAGE_REGEX:="(Fibre Channel|RAID bus controller|Mass storage controller|SCSI storage controller|SATA controller|Serial Attached SCSI controller)( \[[0-9]{4}\])?:"}
# XSOS_SS_CHECK_FIELDS (str: pipe separated field names)
# Configures what SSCHECK() uses to filter fields whose value is > 0.
: ${XSOS_SS_CHECK_FIELDS:="sock_drop|app_limited|dsack_dups|lost|reord_seen|back_log|retrans_total|rq|tq"}
# XSOS_NETSTAT_FILTER_REGEX (str: bash-syntax regular expression)
# Configures what NETSTAT() keys will be printed if their value is > 0
: ${XSOS_NETSTAT_FILTER_REGEX:="drop|err|reset|rst|delay|bad|fail|pause|time|miss|loss|listen|PAWS"}
# XSOS_NETSTAT_HIGHLIGHT_REGEX (str: bash-syntax regular expression)
# Configures what NETSTAT() keys will be highlighted.
#: ${XSOS_NETSTAT_HIGHLIGHT_REGEX:="drop|err|reset|rst|delay|bad|fail|pause|time|miss|loss"}
: ${XSOS_NETSTAT_HIGHLIGHT_REGEX:=""}
# XSOS_NETSTAT_IGNORE_ZERO (bool: y/n)
# Configures whether or not NETSTAT() will ignore fields whose value is 0
: ${XSOS_NETSTAT_IGNORE_ZERO:="y"}
# ==============================================================================
VERSINFO() {
echo "Version info: ${version:2}
See <github.com/ryran/xsos> to report bugs or suggestions"
exit
}
HELP_USAGE() {
echo "Usage: xsos [DISPLAY OPTIONS] [-6abokcfmdtlerngispSFIN] [SOSREPORT ROOT]
or: xsos [DISPLAY OPTIONS] {--B|--C|--F|--M|--D|--T|--L|--R|--N|--G|--I|--P FILE}...
or: xsos [-?|-h|--help]
Display system info from localhost or extracted sosreport"
}
HELP_OPTS_CONTENT() {
echo "
Content options:"
echo "
-a, --all❚show everything
-b, --bios❚show info from dmidecode
-o, --os❚show hostname, distro, SELinux, kernel info, uptime, etc
-k, --kdump❚inspect kdump configuration
-c, --cpu❚show info from /proc/cpuinfo
-f, --intrupt❚show info from /proc/interrupts
-m, --mem❚show info from /proc/meminfo
-d, --disks❚show info from /proc/partitions, dm-multipath, lsblk, df
-t, --mpath❚show info from dm-multipath
-l, --lspci❚show info from lspci
-e, --ethtool❚show info from ethtool
-r, --softirq❚show info from /proc/net/softnet_stat
-n, --netdev❚show info from /proc/net/dev
-g, --bonding❚show bonding and teaming info
-i, --ip❚show info from ip addr (BASH v4+ required)
--net❚alias for: --lspci --ethtool --softirq --netdev --bonding --ip
-s, --sysctl❚show important kernel sysctls
-p, --ps❚inspect running processes via ps
-S, --ss❚inspect running processes via ss
-F, --firewall❚show firewall status
-I, --ifcfg❚|show ifcfg files summary
-N, --netstat❚|show ifcfg files summary" | column -ts❚
}
HELP_OPTS_DISPLAY() {
echo "
Display options:"
# --rhsupport❚tweak os output to focus on RHEL-centric support issues
echo "
--scrub❚remove from output: IP/MAC addrs, hostnames, serial numbers,
❚proxy user & passwords
-6, --ipv6❚parse ip addr output for IPv6 addresses instead of IPv4
-q, --wwid=ID❚restrict dm-multipath output to a particular mpath device,
❚where ID is a wwid, friendly name, or LUN identifier
-u, --unit=P❚change byte display for /proc/meminfo & /proc/net/dev,
❚where P is \"b\" for byte, or else \"k\", \"m\", \"g\", or \"t\"
--threads❚make ps take threads into account (via \`ps auxm\`)
-v, --verbose=NUM❚specify ps verbosity level (0-4, default: 1)
-w, --width=NUM❚change fold-width, in columns (positive number, e.g., 80)
❚\"0\" disables wrapping, \"w\" autodetects width (default)
-x, --nocolor❚disable output colorization
-y, --less❚send output to \`less -SR\`
-z, --more❚send output to \`more\`" | column -ts❚
}
HELP_OPTS_SPECIAL() {
echo "
Special options (BASH v4+ required):"
echo "
--B=FILE❚read from FILE containing \`dmidecode\` dump
--C=FILE❚read from FILE containing /proc/cpuinfo dump
--F=FILE❚read from FILE containing /proc/interrupts dump
--M=FILE❚read from FILE containing /proc/meminfo dump
--D=FILE❚read from FILE containing /proc/partitions dump
--T=FILE❚read from FILE containing \`multipath -v4 -ll\` dump
--L=FILE❚read from FILE containing \`lspci\` dump
--R=FILE❚read from FILE containing /proc/net/softnet_stat dump
--N=FILE❚read from FILE containing /proc/net/dev dump
--G=FILE❚read from FILE containing /proc/net/bonding/xxx dump
--I=FILE❚read from FILE containing \`ip addr\` dump
--P=FILE❚read from FILE containing \`ps aux\` dump
--S=FILE❚read from FILE containing \`ss -peaonmi\` dump
--F=FILE❚read from FILE containing \`systemctl_status_--all\` dump" | column -ts❚
}
HELP_SHORT() {
HELP_USAGE
HELP_OPTS_CONTENT
HELP_OPTS_DISPLAY
HELP_OPTS_SPECIAL
echo -e "\nRun with \"--help\" to see full help page\n"
VERSINFO
}
HELP_EXTENDED() {
HELP_USAGE
echo "Run with \"-h\" to see simplified help page"
HELP_OPTS_CONTENT
HELP_OPTS_DISPLAY
echo "
If no content options are specified, xsos parses the environment variable
XSOS_DEFAULT_VIEW to figure out what information to display. If this variable
is unset at runtime, it is initialized internally as follows:
XSOS_DEFAULT_VIEW='os'
Tweak it to preference by adding additional space-separated MODULE statements,
where MODULE is the same as the long option (e.g. mem, ethtool, netdev). Note
that the --net alias option cannot be used for this purpose. Also note that the
-a / --all option has it's own environment variable: XSOS_ALL_VIEW
If SOSREPORT ROOT isn't provided, the data will be gathered from the localhost;
however, bios, multipath, and ethtool output will only be displayed if running
as root (UID 0). When executing in this manner as non-root, those modules will
be skipped, and a warning printed to stderr.
Sometimes a full sosreport isn't available; sometimes you simply have a
dmidecode-dump or the contents of /proc/meminfo and you'd like a summary..."
HELP_OPTS_SPECIAL
echo "
As is hopefully clear, each of these options requires a filename as an
argument. These options can be used together, but cannot be used in concert
with regular \"Content options\" -- Content opts are ignored if Special options
are detected. Also note: the \"=\" can be replaced with a space if desired.
Re BASH v4+:
BASH associative arrays are used for various things. In short, if running
xsos on earlier BASH versions (e.g. RHEL5), you get ...
* No output colorization
* No -i/--ip
* No parsing of \"Special options\"
Environment variables:
For details of all configurable env variables, view first page of xsos
source. There are vars to change default colors as well as other settings.
Each variable name is prefixed with \"XSOS_\" and the important ones follow.
COLORS FOLD_WIDTH ALL_VIEW DEFAULT_VIEW HEADING_SEPARATOR IP_VERSION
MEM_UNIT NET_UNIT PS_UNIT PS_LEVEL PS_THREADS OUTPUT_HANDLER
SCRUB_IP_HN SCRUB_MACADDR ETHTOOL_ERR_REGEX
"
VERSINFO
}
WARN_NO_UPDATE() {
echo "Warning: v0.6.0 dropped the built-in update feature triggered by -U/--update"
echo "Future v1.x versions might repurpose the -U option"
echo "See https://github.com/ryran/xsos/issues/155 for more info"
exit 64
}
# Help? Version?
case $1 in
-V|--vers|--version) echo "Version info: ${version:2}"; exit ;;
-\?|-h) HELP_SHORT ;;
--help|help) HELP_EXTENDED ;;
-U|--update) WARN_NO_UPDATE >&2 ;;
esac
# GNU getopt short and long options:
sopts='6q:u:v:w:xyzabokcfmdtlerngispSFIN'
lopts='scrub,ipv6,rhsupport,wwid:,unit:,threads,verbose:,width:,nocolor,less,more,all,bios,os,kdump,cpu,intrupt,mem,disks,mpath,lspci,ethtool,softirq,netdev,bonding,ip,net,sysctl,ps,ss,firewall,ifcfg,netstat,B:,C:,F:,M:,D:,T:,L:,R:,N:,G:,I:,P:'
# Check for bad switches
getopt -Q --name=xsos -o $sopts -l $lopts -- "$@" || { HELP_USAGE; exit 64; }
# Setup assoc array for single-file options
unset sfile
[[ $BASH_VERSINFO -ge 4 ]] && declare -A sfile
# Checker for cmdline options
_OPT_CHECK() {
local option chosen_opt check_type valid_opts n s
option=$1
chosen_opt=$(tr '[:upper:]' '[:lower:]' <<<"$2")
check_type=$3
valid_opts=$4
if [[ $check_type == regex ]]; then
grep -E -qs "$valid_opts" <<<"$chosen_opt" && return
case $option in
width)
echo "xsos: option '$option' expects a positive number or 'w' (auto-detect width) or '0' (disable wrapping)"
;;
*)
echo "xsos: option '$option' expects other input, i.e., matching regex '$valid_opts'"=
esac
elif [[ $check_type == range ]]; then
for n in $(seq $valid_opts); do
[[ $n == $chosen_opt ]] && return
done
echo "xsos: option '$option' expects number from range: { ${valid_opts// /-} }"
elif [[ $check_type == naturalnumber ]]; then
grep -E -qs '^[0-9]+$' <<<"$chosen_opt" && return
echo "xsos: option '$option' expects any natural number, including zero"
elif [[ $check_type == string ]]; then
for s in $valid_opts; do
[[ $s == $chosen_opt ]] && return
done
echo "xsos: option '$option' expects one of: { $valid_opts } "
elif [[ $check_type == anystring ]]; then
[[ -n $2 ]] && return
echo "xsos: option '$option' expects a non-null string value"
fi
exit 64
}
# Parse command-line arguments
PARSE() {
unset opts all bios os kdump cpu intrupt mem disks mpath lspci ethtool softirq netdev bonding ip net sysctl ps
until [[ $1 == -- ]]; do
case $1 in
--scrub) XSOS_SCRUB_IP_HN=y XSOS_SCRUB_MACADDR=y XSOS_SCRUB_SERIAL=y XSOS_SCRUB_PROXYUSERPASS=y ;;
-6|--ipv6) XSOS_IP_VERSION=6 ;;
-q|--wwid) _OPT_CHECK "wwid" "$2" anystring
XSOS_MULTIPATH_QUERY=$2; shift
;;
-u|--unit) _OPT_CHECK "unit" "$2" string "b k m g t"
XSOS_MEM_UNIT=$2; XSOS_NET_UNIT=$2; shift
;;
--threads) XSOS_PS_THREADS=y ;;
-v|--verbose) _OPT_CHECK "verbose" "$2" range "0 4"
XSOS_PS_LEVEL=$2; shift
;;
-w|--width) _OPT_CHECK "width" "$2" regex '^[0-9]*$|^w$'
XSOS_FOLD_WIDTH=$2; shift
;;
-x|--nocolor) XSOS_COLORS=n ;;
-y|--less) XSOS_OUTPUT_HANDLER='less -SR' ;;
-z|--more) XSOS_OUTPUT_HANDLER='more' ;;
--rhsupport) XSOS_OS_RHT_CENTRIC=y ;;
-a|--all) opts=y all=y ;;
-b|--bios) opts=y bios=y ;;
-o|--os) opts=y os=y ;;
-k|--kdump) opts=y kdump=y ;;
-c|--cpu) opts=y cpu=y ;;
-f|--intrupt) opts=y intrupt=y ;;
-m|--mem) opts=y mem=y ;;
-d|--disks) opts=y disks=y ;;
-t|--mpath) opts=y mpath=y ;;
-l|--lspci) opts=y lspci=y ;;
-e|--ethtool) opts=y ethtool=y ;;
-r|--softirq) opts=y softirq=y ;;
-n|--netdev) opts=y netdev=y ;;
-g|--bonding) opts=y bonding=y teaming=y ;;
-i|--ip) opts=y ip=y ;;
-s|--sysctl) opts=y sysctl=y ;;
-p|--ps) opts=y ps=y ;;
-S|--ss) opts=y ss=y ;;
-F|--firewall)opts=y firewall=y ;;
-I|--ifcfg) opts=y ifcfg=y ;;
-N|--netstat) opts=y netstat=y ;;
--net) opts=y lspci=y ethtool=y softirq=y netdev=y ip=y firewall=y bonding=y teaming=y ss=y ifcfg=y netstat=y ;;
--B) sfile[B]=$2; shift ;;
--F) sfile[F]=$2; shift ;;
--C) sfile[C]=$2; shift ;;
--M) sfile[M]=$2; shift ;;
--D) sfile[D]=$2; shift ;;
--T) sfile[T]=$2; shift ;;
--L) sfile[L]=$2; shift ;;
--R) sfile[R]=$2; shift ;;
--N) sfile[N]=$2; shift ;;
--G) sfile[G]=$2; shift ;;
--I) sfile[I]=$2; shift ;;
--P) sfile[P]=$2; shift ;;
--S) sfile[S]=$2; shift ;;
esac
shift
done
shift #(to get rid of the '--')
# Set sosroot
sosroot=$@
}
# Call the parser
PARSE $(getopt -u --name=xsos -o $sopts -l $lopts -- "$@")
# If any special option was used appropriately with a file, do that instead of other opts
if [[ $BASH_VERSINFO -ge 4 && -n ${sfile[*]} ]]; then
:
# If BASH is not v4+ and special options were used, fail
elif [[ $BASH_VERSINFO -lt 4 && -n $sfile ]]; then
echo "Special options require use of BASH associative arrays" >&2
echo "i.e., BASH v4.0 or higher (RHEL6/Fedora11 and above)" >&2
exit 32
# Use default view if no content options specified
elif [[ -z $opts ]]; then
for module in $XSOS_DEFAULT_VIEW; do eval $module=y; done
# Else, if "all" option specified, set full view
elif [[ -n $all ]]; then
for module in $XSOS_ALL_VIEW; do eval $module=y; done
fi
# If color should be enabled, taste the rainbow
if [[ $XSOS_COLORS == y && $BASH_VERSINFO -ge 4 ]]; then
c[0]=${c[$XSOS_COLOR_RESET]}
c[H1]=${c[$XSOS_COLOR_H1]}
c[H2]=${c[$XSOS_COLOR_H2]}
c[H3]=${c[$XSOS_COLOR_H3]}
c[H4]=${c[$XSOS_COLOR_H4]}
c[Imp]=${c[$XSOS_COLOR_IMPORTANT]}
c[Warn1]=${c[$XSOS_COLOR_WARN1]}
c[Warn2]=${c[$XSOS_COLOR_WARN2]}
c[Up]=${c[$XSOS_COLOR_IFUP]}
c[Down]=${c[$XSOS_COLOR_IFDOWN]}
c[MemUsed]=${c[$XSOS_COLOR_MEMGRAPH_MEMUSED]}
c[HugePages]=${c[$XSOS_COLOR_MEMGRAPH_HUGEPAGES]}
c[Buffers]=${c[$XSOS_COLOR_MEMGRAPH_BUFFERS]}
c[Cached]=${c[$XSOS_COLOR_MEMGRAPH_CACHED]}
c[Dirty]=${c[$XSOS_COLOR_MEMGRAPH_DIRTY]}
else
unset c
fi
# Properly setup fold setting
if [[ $XSOS_FOLD_WIDTH == w ]]; then
if tty &>/dev/null; then
XSOS_FOLD_WIDTH=$(( $(tput cols) - 8 ))
else
XSOS_FOLD_WIDTH=80
fi
elif [[ $XSOS_FOLD_WIDTH == 0 ]]; then
XSOS_FOLD_WIDTH=99999
fi
# ON TO THE CONTENT MODULE FUNCTIONS!
# -----------------------------------
# ===================================
DMIDECODE() {
# Local vars:
local dmidecode_input
if [[ -z $1 ]]; then
dmidecode_input=$(dmidecode 2>/dev/null)
elif [[ -f $1 ]]; then
dmidecode_input=$(<"$1")
elif [[ -r $1/dmidecode ]]; then
dmidecode_input=$(<"$1/dmidecode")
elif [[ -r $1/sos_commands/kernel.dmidecode ]]; then
dmidecode_input=$(<"$1/sos_commands/kernel.dmidecode")
elif [[ -r $1/sos_commands/hardware/dmidecode ]]; then
dmidecode_input=$(<"$1/sos_commands/hardware/dmidecode")
fi
# If bad dmidecode input, return
if head -n3 <<<"$dmidecode_input" | grep -E -qs 'No such file or directory|No SMBIOS nor DMI entry point found'; then
echo -e "${c[Warn2]}Warning:${c[Warn1]} dmidecode input invalid; skipping bios check${c[0]}" >&2
echo -en $XSOS_HEADING_SEPARATOR >&2
return 1
fi
if [[ $XSOS_SCRUB_SERIAL == y ]]; then
dmidecode_input=$(
gawk -F: '
BEGIN { OFS = ":" }
/^\s+(UUID|Serial Number):/ {
gsub(/[^- ]/, "⣿", $2)
}
{print}
' <<<"$dmidecode_input")
fi
echo -e "${c[H1]}DMIDECODE${c[0]}"
# Prints "<BIOS Vendor>, <BIOS Version>, <BIOS Release Date>"
echo -e "${c[H2]} BIOS:${c[0]}"
gawk 'BEGIN { RS="\nHandle" } /BIOS Information/' <<<"$dmidecode_input" |
gawk -F: -vH3="${c[H3]}" -vH2="${c[H2]}" -vH0="${c[0]}" -vH_IMP="${c[Imp]}" '
/Vendor:/ { Vendor = $2; gsub(/ */, " ", Vendor) }
/Version:/ { Version = $2; gsub(/ */, " ", Version) }
/Release Date:/ { RelDate = $2; gsub(/ */, " ", RelDate) }
/BIOS Revision:/ { BiosRev = $2; gsub(/ */, " ", BiosRev) }
/Firmware Revision:/ { FirmRev = $2; gsub(/ */, " ", FirmRev) }
END {
printf " %sVend:%s%s\n", H3, H0, Vendor
printf " %sVers:%s%s\n", H3, H0, Version
printf " %sDate:%s%s\n", H3, H0, RelDate
printf " %sBIOS Rev:%s%s\n", H3, H0, BiosRev
printf " %sFW Rev:%s %s\n", H3, H0, FirmRev
}
'
# Prints <SYSTEM Manufacturer>, <SYSTEM Product Name>, <SYSTEM Version>, <SYSTEM Serial Number>, <SYSTEM UUID>
echo -e "${c[H2]} System:${c[0]}"
gawk 'BEGIN { RS="\nHandle" } /System Information/' <<<"$dmidecode_input" |
gawk -F: -vH3="${c[H3]}" -vH2="${c[H2]}" -vH0="${c[0]}" -vH_IMP="${c[Imp]}" '
/Manufacturer:/ { Mfr = $2; gsub(/ */, " ", Mfr) }
/Product Name:/ { Product = $2; gsub(/ */, " ", Product) }
/Version:/ { Version = $2; gsub(/ */, " ", Version) }
/Serial Number:/{ Serial = $2 }
/UUID:/ { UUID = $2 }
END {
printf " %sMfr:%s %s\n", H3, H0, Mfr
printf " %sProd:%s%s\n", H3, H0, Product
printf " %sVers:%s%s\n", H3, H0, Version
printf " %sSer:%s %s\n", H3, H0, Serial
printf " %sUUID:%s%s\n", H3, H0, UUID
}
'
# Prints <CPU Manufacturer>, <CPU Family>, <CPU Current Speed>, <CPU Version>
# Prints "<N> of <N> CPU sockets populated, <N> cores/<N> threads per CPU"
# Prints "<N> total cores, <N> total threads"
echo -e "${c[H2]} CPU:${c[0]}"
gawk 'BEGIN { RS="\nHandle" } /Processor Information/' <<<"$dmidecode_input" |
gawk -F: -vH3="${c[H3]}" -vH2="${c[H2]}" -vH0="${c[0]}" -vH_IMP="${c[Imp]}" '
/Status:/ { SumSockets ++; if ($2 ~ /Populated/) PopulatedSockets ++ }
/Core Count:/ { SumCores += $2; CoresPerCpu = $2 }
/Thread Count:/ { SumThreads += $2; ThreadsPerCpu = $2 }
/Manufacturer:/ { if ($2 ~ /^ *$/) next; Mfr = $2; gsub(/ */, " ", Mfr) }
/Family:/ { if ($2 ~ /^ *$|Other/) next; Family = $2; gsub(/ */, " ", Family) }
/Current Speed:/{ if ($2 ~ /^ *$|Unknown/) next; CpuFreq = $2; gsub(/ */, " ", CpuFreq) }
/Version:/ { if ($2 ~ /^ *$/) next; Version = $2; gsub(/ */, " ", Version) }
END {
printf " %s%d of %d CPU sockets populated, %d cores/%d threads per CPU\n",
H_IMP, PopulatedSockets, SumSockets, CoresPerCpu, ThreadsPerCpu
printf " %d total cores, %d total threads\n", SumCores, SumThreads, H0
printf " %sMfr:%s %s\n", H3, H0, Mfr
printf " %sFam:%s %s\n", H3, H0, Family
printf " %sFreq:%s%s\n", H3, H0, CpuFreq
printf " %sVers:%s%s\n", H3, H0, Version
}
'
# Prints "<N> MB (<N> GB) total"
# Prints "<N> of <N> DIMMs populated (max capacity <N>)"
echo -e "${c[H2]} Memory:${c[0]}"
gawk 'BEGIN { RS="\nHandle" } /Physical Memory Array|Memory Device/' <<<"$dmidecode_input" |
gawk -vH3="${c[H3]}" -vH2="${c[H2]}" -vH0="${c[0]}" -vH_IMP="${c[Imp]}" '
/Size:/ {
NumDimmSlots ++
if ($2 ~ /^[0-9]/) {
NumDimms ++
if ($3 ~ /^P/)
SumRam += $2 * 1024 * 1024 * 1024
else if ($3 ~ /^T/)
SumRam += $2 * 1024 * 1024
else if ($3 ~ /^G/)
SumRam += $2 * 1024
else if ($3 ~/^[kK]/)
SumRam += $2 / 1024
else if ($3 ~/^[bB]/)
SumRam += $2 / 1024 / 1024
else
SumRam += $2
}
}
/Maximum Capacity:/ {
if ($3 ~ /^[0-9]/) {
if ($4 ~ /^P/)
SumMaxRam += $3 * 1024 * 1024 * 1024
else if ($4 ~ /^T/)
SumMaxRam += $3 * 1024 * 1024
else if ($4 ~ /^G/)
SumMaxRam += $3 * 1024
else if ($4 ~/^[kK]/)
SumMaxRam += $3 / 1024
else if ($4 ~/^[bB]/)
SumMaxRam += $3 / 1024 / 1024
else
SumMaxRam += $3
}
}
END {
printf " %sTotal:%s %d MiB (%.0f GiB)\n", H3, H0, SumRam, SumRam/1024
printf " %sDIMMs:%s %d of %d populated\n", H3, H0, NumDimms, NumDimmSlots
printf " %sMaxCapacity:%s %d MiB (%.0f GiB / %.2f TiB)\n", H3, H0, SumMaxRam, SumMaxRam/1024, SumMaxRam/1024/1024
}
'
echo -en $XSOS_HEADING_SEPARATOR
}
_CHECK_DISTRO() {
# Local vars:
local OS_INDENT files file
OS_INDENT=" "
# Parse redhat-release if we have it
if [[ ! -r $1/etc/redhat-release ]]; then
distro_release="${c[Imp]}[redhat-release]${c[0]} ${c[RED]}(missing)${c[0]}"
else
# If release is RHEL 4,5,6,7,8 in standard expected format ...
if grep -E -e 'Red Hat Enterprise Linux (AS|ES|Desktop|WS) release 4 \((Nahant|Nahant Update [1-9])\)' \
-e 'Red Hat Enterprise Linux (Client|Server) release 5\.?[0-9]* \(Tikanga\)' \
-e 'Red Hat Enterprise Linux (Client|Workstation|Server) release 6\.?[0-9]* \(Santiago\)' \
-e 'Red Hat Enterprise Linux (Client|Workstation|Server) release 7\.[0-9] \(Maipo\)' \
-e 'Red Hat Enterprise Linux release 8\.[0-9] \(Ootpa\)' \
-qs "$1/etc/redhat-release"; then
# ... And if redhat-release file has more than 1 line ...
[[ $(wc -l <"$1/etc/redhat-release") -gt 1 ]] &&
# ... Then print it in orange
distro_release=${c[ORANGE]}$(sed "1!s/^/$OS_INDENT/" <"$1/etc/redhat-release") ||
# Otherwise, if only 1 line, all is well -- print it normally
distro_release=$(sed "1!s/^/$OS_INDENT/" <"$1/etc/redhat-release")
# If release is not RHEL 4,5,6,7 in standard expected format, freak out
else
distro_release=$(sed "1!s/^/$OS_INDENT/" "$1/etc/redhat-release" 2>/dev/null)
if grep -qi fedora <<<"$distro_release"; then
distro_release=${c[bg_BLUE]}$distro_release
elif grep -E -qi 'alpha|beta' <<<"$distro_release"; then
distro_release=${c[bg_RED]}${c[ORANGE]}$distro_release
else
distro_release=${c[bg_DGREY]}${c[RED]}$distro_release
fi
fi
# Prepend the distro information with "[redhat-release] " and do a little color fun
distro_release="${c[Imp]}[redhat-release]${c[0]} $distro_release${c[0]}"
fi
# Check for any /etc/*-release or /etc/*_version files and add their content to the distro_release variable
files=$(ls "$1"/etc/*{-release,_version} 2>/dev/null | grep -E -sv '/etc/(os|redhat|system|lsb)-release')
if [[ -n $files ]]; then
for file in $files; do
if [[ -r $file ]]; then
distro_release="$distro_release\n$OS_INDENT${c[Imp]}[${file##*/}]${c[0]} $(sed "1!s/^/$OS_INDENT/" <"$file")"
elif [[ -L $file ]]; then
distro_release="$distro_release\n$OS_INDENT${c[Imp]}[${file##*/}]${c[0]} ${c[RED]}(error: broken link)${c[0]}"
else
distro_release="$distro_release\n$OS_INDENT${c[Imp]}[${file##*/}]${c[0]} ${c[RED]}(error: file exists, but cannot read it)${c[0]}"
fi
done
fi
# I don't like blindly sourcing a file -- that provides a vector to screw with this script...
# But in modern Linux boxen this file is standard
# If able to source the new standard /etc/os-release, list it out
if source "$1/etc/os-release" 2>/dev/null; then
distro_release="$distro_release\n$OS_INDENT${c[Imp]}[os-release]${c[0]} $PRETTY_NAME $VERSION"
fi
}
_CHECK_KERNELBUILD() {
# Get kernel build version somehow or another, making sure not to use build offered by rescue mode kernel
# if localhost: get it from the best place, yay
if [[ $1 == / ]]; then
kernel_build=$(</proc/version)
# sosreport: sosreports don't normally contain this.. yet
elif [[ -r "$1/proc/version" ]] && ! grep -qsw rescue "$1/proc/cmdline"; then
kernel_build=$(<"$1/proc/version")
# sosreport: if find it via `dmesg` output file, great
elif ! grep -qsw rescue "$1/proc/cmdline" && kernel_build=$(cat "$1/sos_commands/general/dmesg" "$1/sos_commands/kernel/dmesg" 2>/dev/null | grep -as 'Linux version'); then
:
# sosreport: if find it in var/log/dmesg, woo hoo
elif grep -qs 'Linux version' "$1/var/log/dmesg"; then
kernel_build=$(grep -a 'Linux version' "$1/var/log/dmesg" | tail -n1)
# sosreport: if find it in var/log/messages, lovely
elif grep -qs 'kernel: Linux version' "$1/var/log/messages"; then
kernel_build=$(grep 'kernel: Linux version' "$1/var/log/messages" | tail -n1)
# sosreport: final option: search in all old messages files -- this might be a bad idea
else
# To explain this last one: The goal is to find the most recent instance of "Linux version"
# So this reverse-sorts by filename, searches through all files ending with the most recent file
# This is obviously not very efficient, but it's the only way I've thought of to do it so far
kernel_build=$(find "$1/var/log" -name 'messages?*' 2>/dev/null | sort -r | xargs zgrep -sh 'kernel: Linux version' 2>/dev/null | tail -n1)
fi
# Fix format if necessary
if [[ -n $kernel_build ]]; then
kernel_build=$(sed -e 's,^\[.*\] Linux,Linux,' -e 's,^.*kernel: Linux,Linux,' <<<"$kernel_build")
kernel_buildhost=$(gawk '{print $4}' <<<"$kernel_build")
fi
}
_CHECK_SELINUX() {
# Local vars:
local input_sestatus have_dmesg input_seconfig selinux enforcing selinux_dmesg sestatus_status sestatus_mode sestatus_cfgmode sestatus_policy seconfig_cfgmode seconfig_policy
__cond_print_cfgmode() {
[[ -n $seconfig_cfgmode ]] &&
printf " (default $seconfig_cfgmode)" || printf " (default unknown)"
}
# Grab input from sestatus command if localhost
if [[ $1 == / ]]; then
input_sestatus=$(sestatus 2>/dev/null)
# Else, from $sosroot/sestatus or $sosroot/sos_commands/selinux/sestatus_-b & dmesg
else
input_sestatus=$(gawk '!/\/.*bin/ && NF!=0' "$1/sestatus" 2>/dev/null; gawk '!/\/.*bin/ && NF!=0' "$1/sos_commands/selinux/sestatus_-b" 2>/dev/null)
cat "$1"/var/log/dmesg "$1"/sos_commands/general/dmesg* "$1"/sos_commands/kernel/dmesg 2>/dev/null | grep -E -qis '^SELinux: *Disabled at (boot|runtime)' && selinux_dmesg=disabled
# Could also check /var/log/messages, but it would be too expensive and complicated
# to ensure any hits were for the current boot-cycle
fi
# Read in /etc/selinux/config from sosroot or localhost
input_seconfig=$(cat "$1"/etc/selinux/config 2>/dev/null)
# Set "selinux" and "enforcing" variables per kernel args
eval $(grep -E -ios 'selinux=.|enforcing=.' "$1"/proc/cmdline | tr '[:upper:]' '[:lower:]')
# Check /etc/selinux/config input
if [[ -n $input_seconfig ]]; then
eval $(gawk -F= '
/^SELINUX=/ { cfgmode = $2 }
/^SELINUXTYPE=/ { policy = $2 }
END {
printf "seconfig_cfgmode=%s; seconfig_policy=%s", cfgmode, policy
}
' <<<"$input_seconfig")
fi
# Check sestatus input
if [[ -n $input_sestatus ]]; then
eval $(gawk '
/SELinux status/ { status = $NF }
/Current mode/ { mode = $NF }
/Mode from config file/ { cfgmode = $NF }
/Loaded policy|Policy from config/ { policy = $NF }
END {
printf "sestatus_status=%s; sestatus_mode=%s; sestatus_cfgmode=%s; sestatus_policy=%s",
status, mode, cfgmode, policy
}
' <<<"$input_sestatus")
# Since we have sestatus input, primarily rely on that
if [[ $sestatus_status == disabled ]]; then
# If sestatus says disabled, need to rely on config file for default mode
printf "disabled"; __cond_print_cfgmode
else
# Otherwise, just use sestatus output
printf "$sestatus_mode (default $sestatus_cfgmode)"
fi
# If we don't have sestatus input, things are more complicated...
else
# If we have selinux/enforcing kernel args, use those for current status
if [[ -n $selinux || -n $enforcing ]]; then
case $selinux in
0) printf "disabled" ;;
1) printf "enforcing" ;;
esac
case $enforcing in
0) printf "permissive" ;;
1) printf "enforcing" ;;
esac
__cond_print_cfgmode
# If dmesg from sosreport says disabled, print it out
elif [[ $selinux_dmesg == disabled ]]; then
printf "dmesg says disabled"; __cond_print_cfgmode
# If we only have stuff from /etc/selinux/config
elif [[ -n $seconfig_cfgmode ]]; then
printf "${c[Warn1]}status unknown${c[0]} (default $seconfig_cfgmode)"
# Otherwise, we have no clue ... :(
else
printf "${c[Warn1]}status unknown (default unknown)${c[0]}"
fi
fi
}
_CHECK_GRUB() {
# Local vars:
local grubcfg default
# Other vars that we want to be global, so no local here and no local in modules that call them:
## bad_grubcfg default_missing grub_kernel grub_cmdline
# Find the grub config file
if [[ -f $1/boot/grub/grub.conf ]]; then
# Set grubcfg for grub1
grubcfg=$1/boot/grub/grub.conf
elif [[ -f $1/boot/efi/EFI/redhat/grub.conf ]]; then
# Set grubcfg for rhel UEFI grub1
grubcfg=$1/boot/efi/EFI/redhat/grub.conf
elif [[ -f $1/boot/grub2/grub.cfg ]]; then
# Set grubcfg for rhel grub2
grubcfg=$1/boot/grub2/grub.cfg
elif [[ -f $1/boot/efi/EFI/redhat/grub.cfg ]]; then
# Set grubcfg for rhel UEFI grub2
grubcfg=$1/boot/efi/EFI/redhat/grub.cfg
elif [[ -f $1/boot/grub/grub.cfg ]]; then
# Set grubcfg for debian grub2
grubcfg=$1/boot/grub/grub.cfg
else
# Else, we have nothing
bad_grubcfg="${c[Warn1]}unknown (no grub config file)${c[0]}"
return 1
fi
# Check for read permission
if [[ ! -r $grubcfg ]]; then
# Set a message for later and stop here
bad_grubcfg="${c[Warn1]}unknown (no read permission on ${grubcfg##*/})${c[0]}"
return 1
fi
case "${grubcfg##*/}" in
grub.conf)
# If we have grub.conf, use that
default=$(gawk -F= '/^default=/{print$2}' "$grubcfg" 2>/dev/null)
[[ -z $default ]] && {
default=0; default_missing="${c[Warn1]}(Warning: grub.conf lacks \"default=\"; showing title 0)${c[0]}"
}
# Get the full kernel line for the default title statement
grub_cmdline=$(gawk /^title/,G "$grubcfg" | grep -E -v '^#|^ *#' | sed '1!s/^title.*/\n&/' | gawk -vDEFAULT=$((default+1)) -vRS="\n\n" 'NR==DEFAULT' | grep -o '/vmlinuz-.*')
;;
grub.cfg)
# Otherwise, if we have a grub2 config (grub.cfg), use that
default=$(gawk -F\" '/^set default=/{print$2}' "$grubcfg")
grub_cmdline=$(gawk '/^menuentry.*{/,/^}/' "$grubcfg" | gawk -vRS="\n}\n" -vDEFAULT="$((default+1))" 'NR==DEFAULT' | grep -o '/vmlinuz-.*')
esac
grub_kernel=$(gawk {print\$1} <<<"${grub_cmdline#/vmlinuz-}" 2>/dev/null)
grub_cmdline=$(cut -d' ' -f2- <<<"$grub_cmdline")
}
OSINFO() {
# Local vars:
local distro_release kernel_build kernel_buildhost num_cpu btime hostname hntmp kernel total_plugins yum_plugins num_enabled f rhn_serverURL sURLtmp a rhn_enableProxy rhn_httpProxy rhn_enableProxyAuth rhn_proxyUser rhn_proxyPassword rhnProxyStuff rhsm_hostname rhsm_proxy_hostname rhsm_proxy_port rhsm_proxy_user rhsm_proxy_password rhsmProxyStuff uname systime boottime uptime_input runlevel initdefault timezone
# These functions populate variables for later use
_CHECK_DISTRO "$1"
_CHECK_KERNELBUILD "$1"
_CHECK_GRUB "$1"
# Grab number of cpus from proc/stat
num_cpu=$(gawk '/^cpu[[:graph:]]+/{n++} END{print n}' "$1/proc/stat" 2>/dev/null)
# Grab btime (in seconds since U.Epoch) from proc/stat
btime=$(gawk '/^btime/{print $2}' "$1/proc/stat" 2>/dev/null)
# Grab system hostname & kernel version from /proc first
hostname=$(cat "$1/proc/sys/kernel/hostname" 2>/dev/null)
kernel=$(cat "$1/proc/sys/kernel/osrelease" 2>/dev/null)
# Grab yum plugin stuff
if total_plugins=$(ls "$1"/etc/yum/pluginconf.d/*.conf 2>/dev/null); then
total_plugins=$(wc -l <<<"$total_plugins")
yum_plugins=$(
cd "$1"/etc/yum/pluginconf.d/
gawk -F= '
/^enabled *= */ {
sub(" ", "")
if ($2==1) printf FILENAME" "
}
' *.conf
)
if [[ -n $yum_plugins ]]; then
num_enabled=$(wc -w <<<"$yum_plugins")
yum_plugins=$(sed 's/\.conf /, /g' <<<"$yum_plugins")
yum_plugins=${yum_plugins%, }
yum_plugins="$num_enabled enabled plugins: $yum_plugins"
else
yum_plugins="0 enabled plugins"
fi
else
yum_plugins="${c[Warn1]}No yum plugin info (missing etc/yum/pluginconf.d/*.conf)${c[0]}"
fi
# Grab RHN settings
_get_rhn_cfg() {
local directive=$1 file="$2/etc/sysconfig/rhn/up2date" result=
result=$(gawk -F= "/^$directive *=/{print\$2}" "$file" 2>/dev/null)
result=${result/ /}
if [[ -n $result ]]; then
echo "$directive = $result"
else
return 1
fi
}