commit 0db87b1cfd288fe8779fd624c75bc605e978806f
parent 527298b31677dd8b48a15bacd829d33b3023587f
Author: Remy Noulin <loader2x@gmail.com>
Date: Fri, 7 Jul 2023 21:43:30 +0200
add command 'command' to run a command on all machines
heartbeat.c | 36 +++++++++++++++++++++++++++++++-----
1 file changed, 31 insertions(+), 5 deletions(-)
Diffstat:
1 file changed, 31 insertions(+), 5 deletions(-)
diff --git a/heartbeat.c b/heartbeat.c
@@ -48,6 +48,7 @@ int argc; char **argv;
void printHelp(void);
void config(smallJsont *cfg);
+void runcommand(void);
void probe(char *cfgfile);
/* process arguments on command line
@@ -74,11 +75,6 @@ int main(int ARGC, char** ARGV) {
probe(p);
ret 0;
}
- elif (argc != 2) {
- logE("Too many arguments");
- printHelp();
- ret 1;
- }
elif (eqG(argv[1], "daemon")) {
cleanCharP(h) = expandHome(uHome home "/heartbeat.log");
setLogFile(h);
@@ -102,6 +98,15 @@ int main(int ARGC, char** ARGV) {
}
config(cfg);
}
+ elif (eqG(argv[1], "command")) {
+ // run command on all machines
+ if (argc != 3) {
+ logE("Missing or too many arguments");
+ printHelp();
+ ret 1;
+ }
+ runcommand();
+ }
elif ( eqG(argv[1], "help")
or eqG(argv[1], "-h")
or eqG(argv[1], "--help")
@@ -223,6 +228,27 @@ void config(smallJsont *cfg) {
logG(copyScript);
}
+void runcommand(void) {
+ cleanAllocateSmallJson(cfg);
+ cleanCharP(p) = expandHome(uHome home "/" cfgFile);
+ smallJsont *r = readFileG(cfg, p);
+ if (!r) {
+ logE("Missing %s", p);
+ XFailure;
+ }
+ delElemG(cfg, "port");
+
+ iter(cfg, D) {
+ cast(smallDictt*, d, D);
+ if (hasG(d, "logger")) {
+ logSystem(argv[2]);
+ }
+ else {
+ logSystemf("ssh %s \"%s\"", iK(cfg)/*agent*/, argv[2]);
+ }
+ }
+}
+
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>