wtuyss 发表于 2018-8-24 09:04:02

同时测试多个服务是否存活的脚本[shell和perl]

#!/usr/bin/perl  # wangxiaoyu@w.cn
  # 2009-09-02 01:19:45
  # 2009-09-02 21:38:01
  # 2009-09-03 11:53:57
  # Notice:
  #bash shelldo like above if we want to test the service psad:
  # kill -0 /var/run/psad/psad.pid;echo $?
  # use warnings;
  use strict;
  if (@ARGV0){
  my $proc_name = $ARGV;
  if (-e "/etc/init.d/$proc_name"){
  #open PIDFILE,"/var/run/$proc_name/$proc_name.pid" or open PIDFILE,"/var/run/$proc_name.pid" or print "$proc_name: $!\n";
  open PIDFILE,"/var/run/$proc_name/$proc_name.pid" or open PIDFILE,"/var/run/$proc_name.pid" or print "$proc_name stopped\n";
  while (){
  if (/(\d+)/){
  if (kill(0,$1)){
  print "$proc_name pid: $1 is running ...\n";
  }else{
  print "$proc_name stopped\n";
  };
  };
  };
  close PIDFILE;
  }else{
  print "$proc_name: unrecognized service\n";
  };
  shift;
  }
  sub Usage(){
  my $script_name = `basename $0`;chomp $script_name;
  print "$script_name[]\n";
  print "eg:\n";
  print "$script_name sshd httpd\n";
  };

页: [1]
查看完整版本: 同时测试多个服务是否存活的脚本[shell和perl]