用 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_stringn";}#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_catn";} if ($router_cat =~/^[a-z][a-z][a-z]/){ ? ?$site_code = $&; ?print "site cose is $site_coden";}print "$router_catn";# 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_namen";}}close SITE;print "$site_name $network_catn";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 heren";}#update $update = "/opt/mrtg/mrtg-2.16.2/bin/update $ARGV[0]";unless (system ($update)){ ?print " we got here udpaten";}#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 addn";}$ cat site.txtcip:Shanghai ciz:Shenzhengcib:Beijing (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |