用 perl 把自己个shell 脚本连起来

前端之家收集整理的这篇文章主要介绍了用 perl 把自己个shell 脚本连起来前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

工作中经常要应为更新一个东西,要敲好几个脚本。 现在一句话搞定。

现在用perl 把这几个shell 脚本连起来, 花了半天时间。哈哈,Perl时间长不用就是感觉生疏了。

再次发挥perl 万能胶水的功能。废话少说,上码。

$ cat test.pl#!/usr/local/bin/perl -w####auto update mrtg if this didnt work,please run #1.     Run     cfg txar1.lsi.com  lsi2go        ( lsi2go is the snmp read string )#2.     Run     index txar1.lsi.comName:  #At Name:   prompt,enter description like      Austin MPLS router#3.     Run     update txar1.lsi.com         ( repeat this 3 times until output messages stop )#4.     Run    add_image.pl txar1.lsi.com     (  this add the picture for every link to the index.html)#Note: for the first time,when you create a new device,you have to /var/www/html/mrtg/txar1.lsi.com #And Run cp master.html index.html (then go to step 4)      ##bo.zhang@lsi.com  #2014/04/03$security_string = "lsi2go";$router_cat = $ARGV[0];#$_ = $argv[0];$mpls_router = "";$site_code = "";$site_name = "";$network_cat = "";$cfg = "/opt/mrtg/mrtg\-2.16.2/bin/cfg.snmp2 $ARGV[0] $security_string";unless (system ($cfg)){ print " we have already got the conf,$ARGV[0],$security_string\n";}#decide if this is MPLS netowrk or Internet netowrk#usually,r1 is MPLS network and r2/r5 is Internet networkif ($router_cat =~ /r1/){  $mpls_router = $&;  $network_cat = "MPLS";  print "network cat is $network_cat\n";} if ($router_cat =~/^[a-z][a-z][a-z]/){    $site_code = $&;  print "site cose is $site_code\n";}print "$router_cat\n";# find the site name from site file  if ( ! open SITE,"/opt/mrtg/mrtg\-2.16.2/bin/site.txt"){   die" die error($!)";}  while (<SITE>){chomp;if ( $_ =~ /$site_code:/){  $site_name = $';  print " match is $&\n";  print "$site_name\n";}}close SITE;print "$site_name $network_cat\n";print "$ARGV[0]";#update index $index = "/opt/mrtg/mrtg\-2.16.2/bin/index1 $ARGV[0] $site_name $network_cat";unless (system ($index)){   print " we got here\n";}#update $update = "/opt/mrtg/mrtg\-2.16.2/bin/update $ARGV[0]";unless (system ($update)){  print " we got here udpate\n";}#add image to index.html$add = "/opt/mrtg/mrtg\-2.16.2/bin/add_image.pl $ARGV[0]";unless (system ($add)){  print " we got here add\n";}$ cat site.txtcip:Shanghai ciz:Shenzhengcib:Beijing

猜你在找的Perl相关文章