Perl自动释放Licence启动Verdi
Perl自动释放Licence启动Verdi
在工作中,遇到verdi的License不够的情况,某些人占用了多个License,为及时获得一个可用的License,写了一个perl来kill运行时间最长的进程。
主要功能
- 在perl中,通过(lmstat -a)或者(ps -ef)得到verdi运行情况
- 得到verdi分配情况
- 得到verdi占用最多的用户的使用信息
- 活动该用户使用最长的verdi进程号
具体执行情况
方法一:推荐
方法二:
Perl代码
方法一:推荐
#!/usr/bin/perl
#----------------------------------------------------------------------
#
# Filename: start_verdi
# Description: file function description
#
# Author: 乔木
# Version: 1.0.0
# Create: 2017-12-05 21:29:05
# Last Modified: 2017-12-05 21:29:05
# History: Modify the history
#----------------------------------------------------------------------
#####################################################
# start_verdi
#####################################################
use warnings;
#####################################################
my (@license_stat,$license_flag,@users_license,@users_name,%verdi_user,$mostverdi_user,$total_lic,$use_lic);
@license_stat = `lmstat -f Verdi`;
#####################################################
# get license info
#####################################################
$license_flag = 0;
foreach my $line (@license_stat){
chomp($line);
next if($line =~ /^\s*$/);
if($line =~ /Users of Verdi/){
$line =~ /Total of (\d+) licenses issued; Total of (\d+) licenses in use/;
$total_lic = $1;
$use_lic = $2;
#print("total_lic = $total_lic, use_lic = $use_lic\n");
if($use_lic < $total_lic){
system("verdi @ARGV");
exit;
}
next;
}
if($line =~ /^-----------/){
$license_flag = 0;
#print("$line\n");
last;
}
if($license_flag){
push(@users_license, $line);
}
if($line =~ /"Verdi"/){
$license_flag = 1;
#print("$line\n");
}
}
#####################################################
# handle info
#####################################################
shift(@users_license); #delect first line
foreach my $line (@users_license){
chomp($line);
#print("$line\n");
push(@users_name,(split /\s+/, $line)[1]);
}
#print("users_name = @users_name\n");
#####################################################
# creat user hash >> verdi number
#####################################################
foreach my $user (@users_name){
$verdi_user{$user} += 1;
}
my $user_num= keys %verdi_user;
my $i=0;
foreach (sort {$verdi_user{$a} <=> $verdi_user{$b}} keys %verdi_user) {
$i++;
#printf("%-15s %d verdi\n",$_,$verdi_user{$_} );
if($i == $user_num){
$mostverdi_user = $_;
print("\n$_ has the most verdi: $verdi_user{$_}\n\n");
}
}
#####################################################
# get process info
#####################################################
foreach my $line (@users_license){
chomp($line);
#print("$line\n");
my $user_name = (split /\s+/, $line)[1];
if($user_name eq $mostverdi_user){
#print("$line\n");
$line =~ /\((mm\d.*)\)/;
my $user_process = $1;
#print("$user_process\n");
$user_process =~ s/\// /;
#print("lmremove -h Verdi $user_process\n");
system("lmremove -h Verdi $user_process");
system("verdi @ARGV");
last;
}
}
exit;
方法二:
#!/usr/bin/perl
#----------------------------------------------------------------------
#
# Filename: reqverdi
# Description: file function description
#
# Author:
# Version: 1.0.0
# Create: 2017-12-01 07:23:56
# Last Modified: 2017-12-01 07:23:56
# History: Modify the history
#----------------------------------------------------------------------
#####################################################
# reqverdi
#####################################################
use warnings;
my (%verdi_user,$mostverdi_user,%prosess_hash,$longest_prosess);
#####################################################
# 获得verdi进程信息
#####################################################
my @user_info = `ps -ef | grep Novas | grep -v "grep" | awk '{print \$1}'`;
for(my $i=0;$i < @user_info;$i++){
chomp($user_info[$i]);
#print("$user_info[$i]\n");
}
#####################################################
# creat user hash >> verdi number verdi分配情况
#####################################################
foreach my $user (@user_info){
$verdi_user{$user} += 1;
}
my $user_num= keys %verdi_user;
my $i=0;
foreach (sort {$verdi_user{$a} <=> $verdi_user{$b}} keys %verdi_user) {
$i++;
printf("%-15s %d verdi\n",$_,$verdi_user{$_} );
if($i == $user_num){
$mostverdi_user = $_;
print("\n$_ has the most verdi: $verdi_user{$_}\n\n");
}
}
#####################################################
# get $mostverdi_user info 获得占用最多verdi用户的verdi运行时间
#####################################################
my @most_info = `ps -ef | grep Novas| grep $mostverdi_user| grep -v "grep"`;
#print "@most_info\n";
print("user prosess timer\n");
foreach my $process (@most_info){
my @clump = split /\s+/,$process;
printf("%-10s %-10s %s\n",$clump[0],$clump[1],$clump[6]);
############################
# convert timer
############################
my @day_timer = split /-/,$clump[6];
my @timer = split /:/,$day_timer[-1];
#print("@day_timer @timer\n");
my $timer_convt = 0;
if(@day_timer == 2){
$timer_convt = $day_timer[0]*24*60+$timer[0]*60+$timer[1];
#print("$timer_convt\n");
}
else{
$timer_convt = $timer[0]*60+$timer[1];
#print("$timer_convt\n");
}
$prosess_hash{$clump[1]} = $timer_convt;
}
#####################################################
# get $mostverdi_user the longest run timer prosess number
# 得到运行最长的进程号
#####################################################
my $prosess_num= keys %prosess_hash;
$i=0;
foreach (sort {$prosess_hash{$a} <=> $prosess_hash{$b}} keys %prosess_hash) {
$i++;
#printf("%-15s %s\n",$_,$prosess_hash{$_} );
if($i == $prosess_num){
$longest_prosess = $_;
my $days = int($prosess_hash{$_}/(24*60));
my $hours = int($prosess_hash{$_}%(24*60)/60);
print("\n$_ has run $days day $hours hours\n\n");
}
}
print("kill -9 $longest_prosess\n");
system"kill -9 $longest_prosess";
Perl自动释放Licence启动Verdi的更多相关文章
- OC自动释放池autoreleasepool介绍
自动释放池的机制是:它使得应用在创建新对象时,系统能够有效地管理应用所使用的内存. @autoreleasepool { statements } 在创建新对象时,并且系统未启动ARC特性,那么在使用 ...
- 63 (OC)* NSAutoreleasePool 自动释放池
目录 0:ARC 1: 自动释放池 2:NSAutoreleasePool实现原理 3:autorelease 方法 4: Runloop和Autorelease的关系 5: Using Autore ...
- 刀哥多线程自动释放池autoreleasepool
自动释放池 作用 自动释放对象的 所有 autorelease 的对象,在出了作用域之后,会被自动添加到最近创建的自动释放池中 自动释放池被销毁或者耗尽时,会向池中所有对象发送 release 消息, ...
- Delphi 中的自动释放策略-转
八.使用结构体而不是结构体指针: 很重要 一.指定 Owner 后, 随 Owner 连带释放: //uses Vcl.StdCtrls, Vcl.ExtCtrls; var panel: TPane ...
- Autorelease自动释放池的使用
Autorelease自动释放池的使用 使用ARC开发,只是在编译时,编译器会根据代码结构自动添加了retain.release和autorelease. MRC内存管理原则:谁申请,谁释放 遇到al ...
- iOS---NSAutoreleasePool自动释放原理及详解
前言:当您向一个对象发送一个autorelease消息时,Cocoa就会将该对象的一个引用放入到最新的自动释放池.它仍然是个正当的对象,因此自动释放池 定义的作用域内的其它对象可以向它发送消息.当程序 ...
- OC 内存泄露 自动释放池
花絮:看到下面的代码就想起这么一个调侃: 一个老程序员,功成名就,金盆洗手不在写代码后,决定练练书法.提笔思索良久后在纸上写下:Hello world! /********************** ...
- autoreleasepool自动释放池
示例: @autoreleasepool { ; i[largeNumber; i++) { (因识别问题,该行代码中尖括号改为方括号代替) Person *per = [[Person alloc ...
- paip.jdbc 连接自动释放的测试
paip.jdbc 连接自动释放的测试 使用的mysql jdbc3.1.6 以及5.1.7 测试结果,在没有conn.close()的情况哈.. 作者Attilax 艾龙, EMAIL:146 ...
随机推荐
- Python基础教程之第3章 使用字符串
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32 Type "copyri ...
- Repractise基础篇:Web应用开发七日谈
Repractise基础篇:Web应用开发七日谈 本来想的仅仅是画一个例如以下的七日图来说说Web开发的.随后又想了想这似乎是一个非常棒的Web开发相关的知识介绍.应用开发是一个非常有意思的循环,多数 ...
- hdu 1588 Gauss Fibonacci(矩阵嵌矩阵)
题目大意: 求出斐波那契中的 第 k*i+b 项的和. 思路分析: 定义斐波那契数列的矩阵 f(n)为斐波那契第n项 F(n) = f(n+1) f(n) 那么能够知道矩阵 A = 1 1 1 0 ...
- 如果笔记本的 WIN7 运行很卡,请尝试运行这些批处理
如果笔记本的 WIN7 运行很卡,请尝试运行这些批处理 WIN7是不是很卡?关掉下列服务吧 @echo off rem AppXSvc 为部署应用商店应用程序提供基础结构支持 rem BITS 微软的 ...
- Reentrant 可重入解释
作者:知乎用户链接:https://www.zhihu.com/question/37168009/answer/88086943来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注 ...
- BZOJ4044: [Cerc2014] Virus synthesis(回文树+DP)
Description Viruses are usually bad for your health. How about fighting them with... other viruses? ...
- 【2017 Multi-University Training Contest - Team 7】Hard challenge
[Link]:http://acm.hdu.edu.cn/showproblem.php?pid=6127 [Description] 平面上有n个点,每个点有一个价值,每两个点之间都有一条线段,定义 ...
- SSO单点登录学习总结(2)——基于Cookie+fliter单点登录实例
1.使用Cookie解决单点登录 技术点: 1.设置Cookie的路径为setPath("/").即Tomcat的目录下都有效 2.设置Cookie的域setDomain(&quo ...
- python序列中是否包含某个元素
http://outofmemory.cn/code-snippet/9098/python-list-contains-with-in-not-in theList = ['a','b','c'] ...
- (三)unity4.6Ugui中文教程文档-------概要-UGUI Basic Layout
大家好,我是孙广东. 转载请注明出处:http://write.blog.csdn.net/postedit/38922399 更全的内容请看我的游戏蛮牛地址:http://www.unit ...

