-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
executable file
·43 lines (38 loc) · 1.04 KB
/
main.js
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
#!/usr/bin/env node
/*
* main.js executes 'ssh <username>@<server> w' for all servers given.
* Command line args:
* ./main.js <USERNAME> <SERVERS_FILE>
* SERVERS_FILE is a simple newline-delimited textfile of all the servers.
*
* NOTE: Assumes all servers use port 22 for SSH.
*/
var sys = require('sys');
var fs = require('fs');
var who = require('./who');
var uptime = require('./uptime');
var assert = require('assert');
//////////
// Main //
//////////
var args = process.argv.slice(2);
if (args.length !== 2) {
throw new Error('Usage: ./main.js <USERNAME> <SERVERS_FILE>');
}
fs.readFile(args[1], 'utf-8', function (err, data) {
assert.equal(null, err);
// All the servers!!
data.split('\n').slice(0,-1).map(function (server) {
who.ssh(args[0], server, function (w) {
// This takes the w object and prints the users from each machine
if (w.length > 0) {
sys.puts(
server + ': ' +
w.map(function (obj) {
return obj.USER;
}).join()
);
}
});
});
});