TCL脚本实例+检查IP的脚本源码.doc_第1页
TCL脚本实例+检查IP的脚本源码.doc_第2页
TCL脚本实例+检查IP的脚本源码.doc_第3页
TCL脚本实例+检查IP的脚本源码.doc_第4页
TCL脚本实例+检查IP的脚本源码.doc_第5页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

TCL脚本实例: 检查IP的脚本 1 脚本源码 本脚本系谭勇书写运行结果如下:rootMeil89 bin# ./IP.tcl -f ./cfg/ip_R2.6.0_DRM.cfg= Ping 3 failed! = Ping 6 failed! = Ping 7 failed! = Ping 9 failed! = Ping 6 failed! = Ping 7 failed! = Ping 9 failed! = Ping 1 failed! =invalid IP 10.56.53/31Invalid ip string: 10.56.53/31!= Totally 52 ping successfully as below: 0 1 2 6 0 1 2 3 8 1 2 5 8 1 2 5 6 2 00 01 0 1 2 3 8 1 2 5 8 1 2 5 6 0 0 1 3 4 0 1 7 8 0 1 0 3 7 8 0 0 0 1= Can not ping 8 host as below: 3 6 7 9 6 7 9 1rootMeil89 bin# rootMeil89 bin# ./IP.tcl ping 1-70= Ping 3 failed! = Ping 4 failed! = Ping 7 failed! = Totally 17 ping successfully as below: 1 2 5 6 8 9 0 1 2 3 4 5 6 7 8 9 0= Can not ping 3 host as below: 3 4 7rootMeil89 bin# 今后我们将对这个脚本进行学习.# !/usr/bin/tclsh# !/bin/bash# exec tclsh $0 $set auto_path lappend auto_path file dirname info script ./libpackage require ftppackage require Expectset Usage Usage: n ttclsh $argv0 -f iplist.cfg ?blockn ttclsh $argv0 ping startIp-endIpn ntExample: n tttclsh $argv0 -f iplist.cfg CMS n tttclsh $argv0 ping 0-65n # Define the global variablesset failPing set pingSuccess set flag noset ipListFile set ipBlock set ipList set tmpArgv split string trim join $argv if llength $tmpArgv = 2 set flag lindex $tmpArgv 0 if lindex $tmpArgv 0 = -f set ipListFile lindex $tmpArgv 1 if llength $tmpArgv = 3 set ipBlock lindex $tmpArgv 2 elseif string equal -nocase $flag ping lappend ipList list NULL lindex $tmpArgv 1 else puts $Usage exit else puts $Usage exit# Get the host listif $ipListFile != if $ipBlock = set listBlock getProfile $ipListFile ALL else set listBlock $ipBlock foreach block $listBlock if string equal -nocase $block error | string equal -nocase $block args continue set listKey getProfile $ipListFile $block ALL ONLY_KEY # Insert the key to the ipList like: blockName KeyName foreach key $listKey if string equal -nocase $key error continue lappend ipList list $block $key # Handle each listforeach ip_list $ipList set block lindex $ip_list 0 set ipStr lindex $ip_list 1 set ipKey $ipStr if $block != NULL set ipStr getProfile $ipListFile $block $ipKey if string equal -nocase $ipStr error continue # Get the IP according to the ipStr if set g_ipList GetIP $ipStr = -1 puts Invalid ip string: $ipStr! continue # Ping the IP set result # BadIp: set num 0 foreach ip $g_ipList # Ping the host if PingHost $ip 1 != 0 lappend failPing $ip incr num regexp (0-9+).(0-9+).(0-9+).(0-9+) $ip - p1 p2 p3 p4 append result $p4 puts = Ping $ip failed! = else lappend pingSuccess $ip #puts = Ping $ip successfully! = # Write the result if $block != NULL if $num = 0 set result # OK set tmpStr format %-30s%s string trimright $ipStr $result setProfile $ipListFile $block $ipKey $tmpStr if llength $pingSuccess = 1 puts n= nTotally llength $pingSuccess

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论