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; } }

xoxo,
Andy

2004-12-07 Janitored by Arunbear - added readmore tags, as per Monastery guidelines


In reply to Making chkconfig's output readable by petdance

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.