perl中switch的使用

| 暂无评论 | 暂无引用通告

-->

以下是我用于远程启动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";
 

暂无引用通告

发送引用通告网址: http://supersun.info/mt/mt-tb.cgi/640
如果您想引用这篇日记到您的Blog,请复制上面的链接,放置到您发表文章时的相应界面中。

发表评论

最新资源

  • IMG_1437.JPG
  • line.png
  • bar.png
  • perl_calander.jpg

关于此日记

此日记由 supersun 发表于 2007年5月17日 09:15

此Blog上的上一篇日记应用性能参考SPEC

此Blog上的下一篇日记qmail相关FAQ

首页归档页可以看到最新的日记和所有日记。