-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssh.js
58 lines (53 loc) · 1.43 KB
/
ssh.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const { Client } = require("ssh2");
const dotenv = require("dotenv").config();
const client1 = new Client();
const client2 = new Client();
function booleToGrove(){
client1.on('ready', () => {
console.log('FIRST :: connection ready');
client1.forwardOut(process.env.BOOLE, 22, process.env.GROVE, 22, (err, stream) => {
if (err) {
console.log('FIRST :: forwardOut error: ' + err);
return conn1.end();
}
client2.connect({
sock: stream,
username: process.env.SSH_USER,
password: process.env.SSH_PASSWORD,
tryKeyboard: true,
});
});
}).connect({
host: process.env.BOOLE,
username: process.env.SSH_USER,
password: process.env.SSH_PASSWORD,
});
}
function startBoole(){
client2.on('ready', () => {
console.log('BOOLE:: connection ready');
client2.exec('bash heliosApi.sh ; exit', (err, stream) => {
if (err) {
console.log('BOOLE :: exec error: ' + err);
return client2.end();
}
stream.on('close', (code,signal) => {
client2.end();
console.log("connection closed")
}).on('data', (data) => {
console.log(data.toString());
});
stream.end('exit');
});
}).connect({
host: process.env.BOOLE,
username: process.env.SSH_USER,
password: process.env.SSH_PASSWORD,
});
}
module.exports = {
startBoole,
//startGrove,
//scpToBoole,
//booleToGrove,
}