Make the Linux chkconfig service list easier to read
If you run a Linux box, and you want to see what services start up at which level, you use runlevel:
$ chkconfig acpid 0:off 1:off 2:on 3:on 4:on 5:on 6:off atd 0:off 1:off 2:off 3:on 4:on 5:on 6:off auditd 0:off 1:off 2:on 3:off 4:off 5:off 6:off blk-availability 0:off 1:on 2:on 3:on 4:on 5:on 6:off cpuspeed 0:off 1:on 2:on 3:on 4:on 5:on 6:off crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off cups 0:off 1:off 2:on 3:off 4:off 5:off 6:off ...
Boy is that hard to read at a glance. All the “on” and “off” look very similar to each other, and that blk-availability service’s length screws up the tabbed columns. I decided I needed a better way, which I called cclist.
$ cclist 2345 acpid 345 atd 2 auditd 12345 blk-availability 12345 cpuspeed 2345 crond 2 cups ...
Here’s the code to ~/bin/cclist:
#!/usr/bin/perl open( my $fh, '/sbin/chkconfig --list |' ) or die "Can't open chkconfig: $!"; while (<$fh>) { if ( /^(\S+)(\s+\d:o(n|ff)){7}/ ) { chomp; my @cols = split; my $service = shift @cols; for ( @cols ) { my ( $level, $status ) = split /:/; print $status eq "on" ? $level : " "; } print "\t$service\n"; } else { print; } }