-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautokill.js
More file actions
53 lines (44 loc) · 1.28 KB
/
autokill.js
File metadata and controls
53 lines (44 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import {fetchServers} from 'serverdata.js'
/**
Kills all
*/
export function autoKill(ns, serverArray, scriptNameToKill, verbose) {
const myPid = ns.getRunningScript().pid;
const myScriptName = ns.getScriptName();
const isScriptKill = (scriptNameToKill.length > 0) ? true : false;
let killCount = 0;
for(let i = 0; i < serverArray.length; i++) {
let thisHostName = serverArray[i];
const ps = ns.ps(thisHostName);
for(const script of ps) {
if(isScriptKill && script.filename != scriptNameToKill) {
continue;
}
if(script.pid == myPid) {
if(verbose) {
ns.tprintf("skipped killing this killscript");
}
continue; // don't KYS
}
if(ns.kill(script.pid)) {
killCount ++;
}
}
}
if(verbose) {
ns.tprintf("%s -> autoKill(serverArray[%i], scriptNameToKill=%s, verbose=%s) = killCount %i",
myScriptName, serverArray.length, scriptNameToKill, verbose, killCount
);
}
return killCount;
}
/** @param {NS} ns */
export async function main(ns) {
const verbose = true;
let scriptNameToKill = "";
if(ns.args.length >= 1) {
scriptNameToKill = ns.args[0];
}
let serverArray = fetchServers(ns, "--all", verbose);
autoKill(ns, serverArray, scriptNameToKill, verbose);
}