blob: 4e66d7add66c02f583589ca7c553276964e89fa0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
#! /usr/bin/perl
use Digest::MD5 qw(md5_hex);
$dir = $ENV{'HOME'} . "/.conky/info/";
sub process_server_request {
my $server = shift(@_);
my $fn = shift(@_);
open fl, $fn;
@commands = <fl>;
close fl;
$n_cmd = 0;
foreach $cmd(@commands) {
if ($cmd !~ /^[\/\w\d_]/) {next;}
$n_cmd = $n_cmd + 1;
}
if ($n_cmd > 1) {
$ping = $commands[0];
chomp($ping);
$md5 = md5_hex($ping);
$res = `$ping`;
open(fl, ">$dir/$server-$md5.srv");
print fl $res;
close(fl);
delete($commands[0]);
} else {
$res = 1
}
if ($res > 0) {
foreach $cmd(@commands) {
if ($cmd !~ /^[\/\w\d_]/) {next;}
chomp($cmd);
$md5 = md5_hex($cmd);
open(fl, ">$dir/$server-$md5.srv");
open(cmd, "$cmd |");
while (<cmd>) { print fl; }
close(cmd);
close(fl);
}
}
}
sub process_item {
my $item = shift(@_);
$fn = $ENV{'HOME'} . "/.conky/requests/" . $item;
if (! -f $fn) { return; }
if ($item =~ /^(.*)\.srv$/) {
$server = $1;
process_server_request($server, $fn);
unlink($fn);
}
}
opendir dir, $ENV{'HOME'} . "/.conky/requests/";
@dirlist = readdir dir;
closedir dir;
if ($#ARGV >= 0) {
$item = shift(@ARGV);
process_item($item);
} else {
foreach $item(@dirlist) {
process_item($item);
}
}
|