Handling atrocious output from chkconfig

petdance on 2004-12-05T04:49:22

RedHat has this little utility called chkconfig that helps you manage which services get run at which runlevel on startup. It's pretty handy. Its output format is godawful, however: andy@mungo[~]$ sudo /sbin/chkconfig --list lm_sensors 0:off 1:off 2:on 3:on 4:on 5:on 6:off iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off ntpd 0:off 1:off 2:off 3:on 4:off 5:on 6:off snmpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off rhnsd 0:off 1:off 2:off 3:on 4:on 5:off 6:off rpcgssd 0:off 1:off 2:off 3:on 4:on 5:on 6:off cups-config-daemon 0:off 1:off 2:off 3:on 4:on 5:off 6:off syslog 0:off 1:off 2:on 3:on 4:on 5:on 6:off named 0:off 1:off 2:off 3:off 4:off 5:on 6:off psacct 0:off 1:off 2:off 3:off 4:off 5:off 6:off apmd 0:off 1:off 2:on 3:on 4:on 5:off 6:off cpuspeed 0:off 1:on 2:on 3:on 4:on 5:on 6:off acpid 0:off 1:off 2:off 3:on 4:on 5:on 6:off nifd 0:off 1:off 2:off 3:on 4:on 5:on 6:off messagebus 0:off 1:off 2:off 3:on 4:on 5:on 6:off saslauthd 0:off 1:off 2:off 3:off 4:off 5:off 6:off NetworkManager 0:off 1:off 2:off 3:off 4:off 5:off 6:off gpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off mdmpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off dovecot 0:off 1:off 2:on 3:on 4:on 5:on 6:off nfs 0:off 1:off 2:off 3:off 4:off 5:off 6:off rpcsvcgssd 0:off 1:off 2:off 3:on 4:on 5:on 6:off nscd 0:off 1:off 2:off 3:off 4:off 5:off 6:off irda 0:off 1:off 2:off 3:off 4:off 5:off 6:off mdmonitor 0:off 1:off 2:on 3:on 4:on 5:on 6:off yum 0:off 1:off 2:off 3:off 4:off 5:off 6:off spamassassin 0:off 1:off 2:off 3:off 4:off 5:on 6:off snmptrapd 0:off 1:off 2:off 3:off 4:off 5:off 6:off irqbalance 0:off 1:off 2:off 3:on 4:on 5:on 6:off microcode_ctl 0:off 1:off 2:off 3:off 4:off 5:off 6:off nfslock 0:off 1:off 2:off 3:on 4:on 5:on 6:off bluetooth 0:off 1:off 2:off 3:off 4:off 5:off 6:off haldaemon 0:off 1:off 2:off 3:on 4:on 5:on 6:off readahead_early 0:off 1:off 2:off 3:off 4:off 5:on 6:off vncserver 0:off 1:off 2:off 3:off 4:off 5:off 6:off smartd 0:off 1:off 2:on 3:on 4:on 5:on 6:off sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off winbind 0:off 1:off 2:off 3:off 4:off 5:off 6:off atd 0:off 1:off 2:off 3:on 4:on 5:on 6:off diskdump 0:off 1:off 2:off 3:off 4:off 5:off 6:off portmap 0:off 1:off 2:off 3:on 4:on 5:on 6:off netfs 0:off 1:off 2:off 3:on 4:on 5:on 6:off smb 0:off 1:off 2:on 3:on 4:on 5:on 6:off pcmcia 0:off 1:off 2:on 3:on 4:on 5:on 6:off lisa 0:off 1:off 2:off 3:off 4:off 5:off 6:off kudzu 0:off 1:off 2:off 3:on 4:on 5:on 6:off readahead 0:off 1:off 2:off 3:off 4:off 5:on 6:off xfs 0:off 1:off 2:on 3:on 4:on 5:on 6:off mDNSResponder 0:off 1:off 2:off 3:on 4:on 5:on 6:off rpcidmapd 0:off 1:off 2:off 3:on 4:on 5:on 6:off postfix 0:off 1:off 2:on 3:on 4:on 5:on 6:off mailman 0:off 1:off 2:on 3:on 4:on 5:on 6:off ypbind 0:off 1:off 2:off 3:off 4:off 5:off 6:off netdump 0:off 1:off 2:off 3:off 4:off 5:off 6:off anacron 0:off 1:off 2:on 3:on 4:on 5:on 6:off cups 0:off 1:off 2:on 3:on 4:on 5:on 6:off netplugd 0:off 1:off 2:off 3:off 4:off 5:off 6:off autofs 0:off 1:off 2:off 3:on 4:on 5:on 6:off Quick, what are you running at runlevel 2? How can I easily pick out information? I can't scan the columns very easily. Besides, if you have a table and your values are boolean, don't make them be "Yes" and "No" or "On" and "Off", but a value and empty space.

So here's how I cleaned it up: andy@mungo[~]$ /sbin/chkconfig --list | ./cclist 2345 lm_sensors 2345 iptables 2345 network 3 5 ntpd snmpd 34 rhnsd 345 rpcgssd 34 cups-config-daemon 2345 syslog 5 named psacct 234 apmd 12345 cpuspeed 345 acpid 345 nifd 345 messagebus saslauthd NetworkManager 2345 gpm mdmpd 2345 crond 2345 dovecot nfs 345 rpcsvcgssd nscd irda 2345 mdmonitor yum 5 spamassassin snmptrapd 345 irqbalance microcode_ctl 345 nfslock bluetooth 345 haldaemon 5 readahead_early vncserver 2345 smartd 2345 sshd winbind 345 atd diskdump 345 portmap 345 netfs 2345 smb 2345 pcmcia lisa 345 kudzu 5 readahead 2345 xfs 345 mDNSResponder 345 rpcidmapd 2345 postfix 2345 mailman ypbind netdump 2345 anacron 2345 cups netplugd 345 autofs So much better. Oh my, look, named is only running if I'm at runlevel 5. I wouldn't have noticed that from the first version.

Simple little code follows. Golf it if you must, but I'm not really interested in how I could make it better unless I'm doing something significantly stupid. andy@mungo[~]$ more cclist while (<>) { 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; } }


Simpler?

Dom2 on 2004-12-05T10:51:01

In the past I've always piped the output to get what I want.
% chkconfig --list | sort | grep 3:on

Your way looks a lot more flexible!

-Dom

Suggestions to make it easier to scan vertically

Aristotle on 2004-12-05T16:11:29

  • A space between the columns
  • Using Term::ANSIColor to colour-code the runlevels

Re:Suggestions to make it easier to scan verticall

Purdy on 2004-12-06T12:45:22

I see I wasn't the only one inspired by the 2nd day of the Advent Calendar! ;)

Translated

rafael on 2004-12-06T10:02:33

With LC_ALL=fr_FR, it's a lot more horrible, because columns are not even aligned.

See an example:

sound           0:arrêt 1:arrêt 2:marche        3:marche        4:marche        5:marche        6:arrêt
dm              0:arrêt 1:arrêt 2:arrêt 3:arrêt 4:arrêt 5:marche        6:arrêt
kheader         0:arrêt 1:arrêt 2:marche        3:marche        4:arrêt 5:marche        6:arrêt

Re:Translated

nicholas on 2004-12-06T20:37:50

Whereas this all looks OK in Mandrake? But en_US looks particulary bad? :-)