Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Making chkconfig's output readable

by petdance (Parson)
on Dec 05, 2004 at 05:00 UTC ( [id://412460]=CUFP: print w/replies, xml ) Need Help??

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

Replies are listed 'Best First'.
Re: Making chkconfig's output readable
by fireartist (Chaplain) on Dec 07, 2004 at 10:59 UTC

    ++
    I'd probably also pipe it through sort first.

    /sbin/chkconfig --list | sort | ./cclist
Re: Making chkconfig's output readable
by wolfger (Deacon) on Dec 09, 2004 at 19:23 UTC
    Nicely done. I would add the option to have listings by service (as you did) or by runlevel (runlevel 1 has these processes, runlevel 2 has...)

    --
    Linux, sci-fi, and Nat Torkington, all at Penguicon 3.0
Re: Making chkconfig's output readable
by TVSET (Chaplain) on Dec 16, 2004 at 10:38 UTC
    I don't see what is wrong with chkconfig's output. If you are interested in one specific service you can do either "chkconfig --list someservice" or "chkconfig --list | grep someservice". If you want to know which services run in runlevel 2, you can do "chkconfig --list | grep 2:on".
      I want to look at all of them, at a glance. The "on" and "off" strings are unnecessarily obscuring. The best way to say "no" is with whitespace. It makes you think, rather than make the answers incredibly obvious.

      Do you honestly not see the difference between the default output and what I put together?

      xoxo,
      Andy

        I really liked your idea. I couldn't help but golf a little. I only output what's on. /sbin/chkconfig --list | perl -nle '$s=(split)[0];s/(\d):on/$a{$s}.=$1/ge;s/(\w+):\s+(on)/$a{"xinetd  -> $1"}=$2/e; END{print "$_: $a{$_}" for sort keys %a}' Score yours: 186 swings; 147 swings if I turn all your vars into single characters. mine: 116 swings. Just having fun!
Re: Making chkconfig's output readable
by dominix (Deacon) on Dec 09, 2004 at 06:39 UTC
    ++
    however,
    I'll recomend to un-localise output for those who got locale set.
    LANG=C chkconfig ... or export LANG=C sudo chkconfig ...
    --
    dominix

      Or simply LANG=C sudo chkconfig.

      Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://412460]
Approved by Mr. Muskrat
Front-paged by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-24 22:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found