LINUX.ORG.RU

скрипт для мониторинга UPS


0

0

Скачал вот этот скрипт:

_____________________________

#! /usr/bin/wish

set timeout 5000
set statusFile "/etc/apcupsd.status"

#

frame .f -relief ridge -border 2
label .f.l -text "Util: " -font
-adobe-helvetica-medium-r-normal-*-14-*-*-*-*-*-*-*
label .f.s -foreground blue -font
-adobe-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*
pack .f.l .f.s -side left

frame .s -relief ridge -border 2
label .s.l -text "Batt: " -font
-adobe-helvetica-medium-r-normal-*-14-*-*-*-*-*-*-*
label .s.s -foreground blue -font
-adobe-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*
pack .s.l .s.s -side left

frame .v -relief ridge -border 2
label .v.l -text "Volt: " -font
-adobe-helvetica-medium-r-normal-*-14-*-*-*-*-*-*-*
label .v.s -foreground blue -font
-adobe-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*
pack .v.l .v.s -side left

frame .e -relief ridge -border 2
label .e.l -text "Event: " -font
-adobe-helvetica-medium-r-normal-*-14-*-*-*-*-*-*-*
label .e.s -foreground blue -font
-adobe-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*
pack .e.l .e.s -side left

pack .f .s .v .e -side left

wm title . "APC UPS status"

set entered 0
set mTime 0

bind . <Enter> {
set entered 1
set mTime 0
doUpdate
}

bind . <Leave> {
set entered 0
set mTime 0
doUpdate
}

___________________

он выдает пустое окно если запустить
/usr/bin/wish

а если сам исполняемый файл то вот это:

[user@localhost ~]$ ./ups
Error in startup script: value for "-font" missing
while executing
"label .f.l -text "Util: " -font"
(file "./ups" line 9)
[user@localhost ~]$

я в скриптинге слабоват, поэтому прошу вашей помощи.

девайс APC 500 RS.

Заранее благодарен.

★★

просто укажи шрифт на той же строке -

label .f.l -text "Util: " -font -adobe-helvetica-medium-r-normal-*-14-*-*-*-*-*-*-*

dreamer ★★★★★
()

то есть вот это должно быть в одну строку -

label .f.l -text "Util: " -font -adobe-helvetica-medium-r-normal-*-14-*-*-*-*-*-*-*

dreamer ★★★★★
()
Ответ на: комментарий от dreamer

кстати не работает, и весь скрипт не поместился аочемуто щас дам целиком и скажу чо он мне еще выдает:

#! /usr/bin/wish

set timeout 5000
set statusFile "/etc/apcupsd.status"

#

frame .f -relief ridge -border 2
label .f.l -text "Util: " -font -adobe-helvetica-medium-r-normal-*-14-*-*-*-*-*-*-*
label .f.s -foreground blue -font -adobe-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*
pack .f.l .f.s -side left

frame .s -relief ridge -border 2
label .s.l -text "Batt: " -font -adobe-helvetica-medium-r-normal-*-14-*-*-*-*-*-*-*
label .s.s -foreground blue -font -adobe-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*
pack .s.l .s.s -side left

frame .v -relief ridge -border 2
label .v.l -text "Volt: " -font -adobe-helvetica-medium-r-normal-*-14-*-*-*-*-*-*-*
label .v.s -foreground blue -font -adobe-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*
pack .v.l .v.s -side left

frame .e -relief ridge -border 2
label .e.l -text "Event: " -font -adobe-helvetica-medium-r-normal-*-14-*-*-*-*-*-*-*
label .e.s -foreground blue -font -adobe-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*
pack .e.l .e.s -side left

pack .f .s .v .e -side left

wm title . "APC UPS status"

set entered 0
set mTime 0

bind . <Enter> {
set entered 1
set mTime 0
doUpdate
}

bind . <Leave> {
set entered 0
set mTime 0
doUpdate
}


proc doUpdate {} {
global mTime statusFile timeout
after $timeout doUpdate

set currentTime [file mtime $statusFile]

if { $currentTime <= $mTime } {
return
}
set mTime $currentTime

set f [open $statusFile "r"]

# APC : Jul 09 09:11:22
# CABLE : APC Cable 940-0095A
# UPSMODEL : BackUPS Pro
# UPSMODE : Stand Alone
# LINEFAIL : OK
# BATTSTAT : OK
# LINEVOLT : OK
# LASTEVNT : LINE VOLTAGE INCREASE

global eventTime
gets $f; gets $f; gets $f; gets $f
foreach entry {f s v} {
.${entry}.s configure -text "N/A"
}
while { 1 } {
parseLine [gets $f]
if { [eof $f] } break
}
close $f
}

proc now {} {
return [clock format [clock seconds]]
}

set lastValue ""
set eventTime [now]

proc parseLine { line } {
set l [split $line]
set keyword [lindex $l 0]
set value [getValue $l]
switch $keyword {
"LINEFAIL" {
setValue .f.s $value
}
"BATTSTAT" {
setValue .s.s $value
}
"LINEVOLT" {
setValue .v.s $value
}
"LASTEVNT" {
global entered
if { $entered == 1 } {
global eventTime
setValue .e.s $eventTime
} else {
setValue .e.s $value
}
global lastValue
if { "$value" != "$lastValue" } {
global eventTime
set eventTime [now]
set lastValue $value
}
}
}
}

proc setValue { widget text } {
$widget configure -text $text
foreach pattern { fail off down } {
if { [regexp ".*${pattern}.*" [string tolower $text]] } {
$widget configure -foreground red
return
}
}
$widget configure -foreground blue
}

proc getValue { line } {
return [string range $line [expr [string first ":" $line] + 2] end]
}

doUpdate

строчки я выровнял как ты сказал, но он мне пишет вот что:

[user@localhost ~]$ ./ups
Error in startup script: could not read "/etc/apcupsd.status": no such file or directory
while executing
"file mtime $statusFile"
(procedure "doUpdate" line 5)
invoked from within
"doUpdate"
(file "./ups" line 136)
[user@localhost ~]$

veent ★★
() автор топика
Ответ на: комментарий от dreamer

нет, небыло, а вот после его создания прога запустилась, но поля под названием:

Util, Batt, Volt - все с пометкой N/A т.е. я так понимаю - недоступны ... что делать то? - это раз!

и два - к сведению (может поможет) :)
при попытке запустить в консоли apctest вот что получается:

[root@localhost user]# apctest


2006-10-09 00:27:08 apctest 3.10.18 (21 July 2005) mandrake
Checking configuration ...
Attached to driver: usb
sharenet.type = DISABLE
cable.type = USB_CABLE

You are using a USB cable type, so I'm entering USB test mode
mode.type = USB_UPS
Setting up the port ...
apctest FATAL ERROR in apcdevice.c at line 77
Unable to create UPS lock file.
apctest FATAL ERROR in apcdevice.c at line 77
Unable to create UPS lock file.
apctest error termination completed
[root@localhost user]#


найти этого самого apcdevice.c не смог чтоб поглядеть чего там на строчке 77 находится такого непонятного, ну и вам показать... но может кто в курсе ?

veent ★★
() автор топика
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.