alpine-server/config-files/ups.c

52 lines
1,019 B
C
Raw Normal View History

2022-10-17 20:02:47 +02:00
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int main()
{
unsigned int chargelim = 80;
unsigned int charge = 100;
unsigned int voltagelim = 210;
unsigned int voltage = 240;
FILE *fp;
char path[1024];
while(charge > chargelim || voltage > voltagelim)
{
sleep(20);
fp = popen("/usr/bin/upsc ups@{domain} battery.charge 2>&1 |grep -v 'Init SSL'", "r");
if(fgets(path, sizeof(path), fp) != NULL)
{
charge = atoi(path);
pclose(fp);
}
else
{
pclose(fp);
system("poweroff");
}
fp = popen("/usr/bin/upsc ups@{domain} input.voltage 2>&1 |grep -v 'Init SSL'", "r");
if(fgets(path, sizeof(path), fp) != NULL)
{
voltage = atoi(path);
pclose(fp);
}
else
{
pclose(fp);
system("poweroff");
}
}
system("poweroff");
return 0;
}