ubuntu下使用 chkconfig 是一种习惯


ubuntu下使用 chkconfig 是一种习惯

习惯了chkconfig命令, 闲来写了个脚本模拟下, 步骤很简单。 如下:

第一步, 安装sysv-rc-conf

sudo apt install sysv-rc-conf

第二步, 将如下脚本放于/usr/sbin目录下

 

gord@gord:/usr/sbin$ cat chkconfig 
#!/usr/bin/perl

use strict;
#use warnings;

my $param1 = $ARGV[0];
my $param2 = $ARGV[1];

if ( defined $param2 ){
    if ( $param1 =~ /list/ ){
        system("sysv-rc-conf --list $param2");
    }elsif( $param2 eq 'on' ){
        system("sysv-rc-conf --level 2345 $param1 on");
        system("sysv-rc-conf --list $param1");
    }elsif( $param2 eq 'off' ){
        system("sysv-rc-conf --level 2345 $param1 off");
        system("sysv-rc-conf --list $param1");
        }else{
            print("Usage: chkconfig < option > | --list | [ service_name [ command  < on | off > ] ]\n");
            exit(1);
    }
}else{
    system("sysv-rc-conf --list $param2");

第三步, 赋予权限

chmod 755 chkconfig

使用下,看看效果

gord@gord:/usr/sbin$ chkconfig --list postfix
postfix      0:off    1:off    2:on    3:on    4:on    5:on    6:off

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM