在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
日志滚动,获取 tail -f 里的信息 如果 存在“Too many open files”那么重启apache #!/usr/bin/perl my $now=localtime(time); &write_log("$now start reahache.pl\n" . '----------------------------------' . "\n"); open Tail, '/usr/bin/tail -f /etc/httpd/logs/error_log |' or die "Pipe failed: $!\n"; while (<Tail>){ my $in = <Tail>; if($in=~/Too many open files/i){ my $get_str_cmd=qx(service httpd restart); my $log_str = "$in\n" . "$get_str_cmd\n"; &write_log($log_str); sleep 10; } } close Tail; sub write_log { open(TEMP_LOG,">>/lcx/restartLog.log") || die"err: $! \n"; my $write_str=$_[0]; syswrite(TEMP_LOG,"$write_str\n\n\n"); close(TEMP_LOG); }
|
请发表评论