ASPN ActiveState Programmer Network  
ActiveState, a division of Sophos
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups
Submit Recipe
My Recipes

All Recipes
All Cookbooks


View by Category

Title: Script checking availability of network servers
Submitter: Alex Khokhlov (other recipes)
Last Updated: 2007/08/27
Version no: 1.1
Category: System Administration

 

Not Rated yet


Description:

Script checking availability of network servers
If the server is not accessible, starts action
The necessary data are read from a text file

The file of the data contains lines of a kind:

smtp_server:25:any_executed_program:my_smtp_server
httpd_daemon:80:ps:corp_web_server

Source: Text Source

#!/bin/sh
#the next line restarts using tclsh\
exec tclsh8.4 "$0" "$@"

set msg "is down"
set file "hostslist"
set hf [open $file r+ 440]
set glist [] 
foreach line [split [read $hf] \n]  {
	set ls [split $line :]
	lappend glist $ls 
}
close $hf
set fd [open logfile w+ 440]
puts $fd $glist
close $fd

proc connect {host port} {
global s
set s [socket $host $port]
}
proc alert { host res desc msg} {
puts "$host $res $desc $msg"
}
proc action {a} {
puts stdout [exec $a]
}

set n [llength $glist]
set n1 [llength [lindex $glist 0]]

for {set i 0 } {$i<[expr $n-1]} {incr i }  { 
set i1 0;set i2 [expr $n1-3];set i3 [expr $n1-2];set i4 [expr $n1-1] 
set host [lindex [lindex $glist $i] $i1]
set port [lindex [lindex $glist $i] $i2]
set act  [lindex [lindex $glist $i] $i3]
set desc [lindex [lindex $glist $i] $i4]
if {[catch {connect $host $port} result]} {
alert $host $result $desc $msg  
action $act
} else {
puts "$desc is ready"
  }
}

The license for this recipe is available here.

Discussion:



Add comment

No comments.



Highest rated recipes:

1. With busy cursor

2. Get widget info

3. Simplified mega-widiget ...

4. Supporting mouse wheel ...

5. Multi-character split

6. LCD Number Display

7. Check creditcard numbers ...

8. A minimal debugger

9. Socket based communicatio...

10. WSCP - showServerStatus




Privacy Policy | Email Opt-out | Feedback | Syndication
© 2006 ActiveState Software Inc. All rights reserved.