-->
以下是我用于远程启动jboss服务器的脚本,此处刚好可以学习switch的使用
#!/usr/bin/perl -w
use strict;
sub useage(){
print "用法:$0 1|2|3|4 r|s|rs\n";
}
sub jboss_oprate(){
my ($host,$oprate)=@_;
system("ssh","$host",". /etc/profile;$oprate");
}
print "本程序用于重启rs1 rs2 rs3 rs4中的jboss服务器
";
useage(),exit if $#ARGV != 1;
my $host=shift;
my $oprate=shift;
SWITCH: {
$host == 1 and $host="rs1",last;
$host == 2 and $host="rs2",last;
$host == 3 and $host="rs3",last;
$host == 4 and $host="rs4",last;
useage(),exit;
}
SWITCH: {
$oprate eq "r" and $oprate = "jbr",last;
$oprate eq "s" and $oprate = "jbs",last;
$oprate eq "rs" and $oprate = "jbrestart",last;
useage(),exit;
}
print "现在对服务器$host进行$oprate操作:\n";
&jboss_oprate($host,$oprate);
print "程序运行完毕\n";

发表评论