您的位置:首页 > 运维架构 > Linux

Perl批量执行Linux安装程序和脚本

2013-01-29 00:03 477 查看
转载http://www.oschina.net/code/snippet_222150_7901

#!/usr/bin/perl
#use Cwd;
sub ExecuteAll(){
local($dir) = @_;
opendir(DIR,"$dir"|| die "can't open $dir");
local @files =readdir(DIR);
closedir(DIR);
for $file (@files){
next if($file=~m/\.$/ || $file =~m/\.\.$/);
if ($file =~/\.(sh)$/i){
system "xterm -e bash \"$dir\/$file\"";
}
elsif($file =~/\.(bin|run|bundle)$/i){
system "xterm -e \"$dir\/$file\"";
}
elsif($file =~/\.(pl)$/i && $file != $0){
system "xterm -e perl \"$dir\/$file\"";
}
elsif($file =~/\.(class)$/i){
$file =~ s/(.*)\.(.*)/$1/;
system "xterm -e java \"$dir\/$file\"";
}
elsif($file =~/\.(rpm)$/i){
system "xterm -e rpm -ivh \"$dir\/$file\"";
}
elsif($file =~/\.(rb)$/i){
system "xterm -e ruby \"$dir\/$file\"";
}
elsif($file =~/\.(py)$/i){
system "xterm -e python \"$dir\/$file\"";
}
elsif($file =~/\.(jar)$/i){
system "xterm -e java -jar \"$dir\/$file\"";
}
elsif(-d "$dir/$file"){
ExecuteAll("$dir/$file" );
}
}
}
&ExecuteAll(getcwd);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  perl