只开启应用服务,并关闭所有不相关的系统服务.提高性能.

  1. #!/usr/bin/perl -w 
  2. use warnings; 
  3. use strict; 
  4. my %myservices = ( 
  5.                 "atd" => "1"
  6.                 "crond" => "1"
  7.                 "netfs" => "1"
  8.                 "autofs" => "1"
  9.                 "sshd" => "1"
  10.                 "syslog" => "1"
  11.                 "network" => "1"
  12.                 "nfslock" => "1"
  13. ); 
  14. #my($sec,$min,$hour,$day,$mon,$year)=localtime; 
  15. #my $year=$year+1900; 
  16. chomp(my $date=`date +%F`); 
  17. my $file="/tmp/.chkconfig.$date.log"
  18. unlink $file; 
  19. sub Getservices { 
  20.         my $cmd="chkconfig --list"
  21.         my @chklist = `$cmd`; 
  22.         my @services; 
  23. #       print "@chklist\n"
  24.                 foreach (@chklist){ 
  25.                         chomp; 
  26.                         s/^\s+//; 
  27.                         s/\s+$//; 
  28.                         next if $_  eq ''
  29.                         my @num=split /\s+/,$_; 
  30.                         next if scalar@num !=8; 
  31.                         push (@services,(split /\s+/,$_)[0]); 
  32.   } 
  33.         return @services; 
  34. sub savelog { 
  35.         `/bin/echo "@_">>$file`; 
  36. sub Changeservices { 
  37.         my $off=0; 
  38.         foreach (Getservices()){ 
  39.                 next if $myservices{$_}; 
  40.                 print " $_ at all level to off\n"
  41.                 my $cmd="chkconfig --level 0123456 $_ off"
  42.                         `$cmd`; 
  43.                 $off++; 
  44.                 savelog($cmd); 
  45.  } 
  46.                 foreach (keys %myservices){ 
  47.                         my $cmd="chkconfig --level 35 $_ on"
  48.                                 `$cmd`; 
  49.                         print " $_ at 35 level to on\n"
  50.                         savelog($cmd); 
  51.   } 
  52.         printf "OFF_services: %d\nON_services: %d\nALL_services: %d\n",$off,scalar(keys %myservices),scalar Getservices(); 
  53. &Changeservices();