优化chkconfig

只保留系统服务: crond /network /sshd /rsyslog /sysstat 其他服务全部关闭

首先将所有 3:on的服务名过滤出来,然后 grep -vE 排除需要的服务

#!/bin/bash

. /etc/init.d/functions
service=`chkconfig --list | grep 3:on | awk '{print $1}'| grep -vE "crond|sshd|network|rsyslog|sysstat"`

for serve in $service;do
        chkconfig $serve off
        action "$serve off" /bin/true
done

 执行结果:

[root@rhel6 script]# bash chkconfig.py 
abrtd off                                                  [  OK  ]
acpid off                                                  [  OK  ]
atd off                                                    [  OK  ]
auditd off                                                 [  OK  ]
autofs off                                                 [  OK  ]
blk-availability off                                       [  OK  ]
lvm2-monitor off                                           [  OK  ]
mcelogd off                                                [  OK  ]
mcollective off                                            [  OK  ]
mysqld off                                                 [  OK  ]
nfslock off                                                [  OK  ]
nginxd off                                                 [  OK  ]
ntpd off                                                   [  OK  ]
portreserve off                                            [  OK  ]
rpcbind off                                                [  OK  ]
rsyncd off                                                 [  OK  ]
udev-post off                                              [  OK  ]

ubuntu中 chkconfig对应的命令是:sysv-rc-conf

原文地址:https://www.cnblogs.com/vincenshen/p/6610242.html