diff options
Diffstat (limited to 'scripts/conky_process_requests.pl')
-rwxr-xr-x | scripts/conky_process_requests.pl | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/scripts/conky_process_requests.pl b/scripts/conky_process_requests.pl new file mode 100755 index 0000000..4e66d7a --- /dev/null +++ b/scripts/conky_process_requests.pl @@ -0,0 +1,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); + } +} |