changed syntax
This commit is contained in:
parent
c39bb24c42
commit
5a771084c4
6 changed files with 0 additions and 0 deletions
51
config-files/ups.c
Normal file
51
config-files/ups.c
Normal file
|
@ -0,0 +1,51 @@
|
|||
#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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue