From ef8cb5cb98c44fd52284e039bff8a1d690d74b39 Mon Sep 17 00:00:00 2001 From: Ashelyn Rose Date: Mon, 20 Nov 2023 18:29:12 -0700 Subject: [PATCH] cleanup script --- src/cleanup.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/cleanup.ts diff --git a/src/cleanup.ts b/src/cleanup.ts new file mode 100644 index 0000000..5c7e2ff --- /dev/null +++ b/src/cleanup.ts @@ -0,0 +1,18 @@ +import { NS } from "@ns"; +import { getControllerState } from "/lib/types-and-constants"; + +export async function main(ns : NS) : Promise { + const [script] = ns.args + + const datafileState = getControllerState(ns) + const adminServers = datafileState.knownServers.filter(s => s.hasAdminRights) + + for(const server of adminServers) { + const processes = ns.ps(server.hostname) + + for (const process of processes) { + if (process.filename === script) + ns.kill(process.pid) + } + } +}