-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathdemo.js
54 lines (45 loc) · 1.38 KB
/
demo.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
'use strict';
const autossh = require('./index.js');
// open 5 ssh tunnels
// for (let i = 0; i < 5; i++) {
// set up config
autossh({
host: 'xyz.xy.xyz.yz', // enter host address
username: 'root', // enter username
localPort: 'auto', // 'auto' or port number
remotePort: 5432
})
// listen for errors
.on('error', err => {
console.error('ERROR: ', err);
})
// listen for connection
.on('connect', connection => {
console.log('\n**connected**');
console.log('localPort: \t' + connection.localPort);
console.log('pid: \t\t' + connection.pid);
console.log(`tunnel established from localhost:${connection.localPort} to ${connection.host}:${connection.remotePort} as ${connection.username}`);
});
// }
/* Possible output example (localPort results are be random)
**connected**
localPort: 39570
pid: 7477
tunnel established from localhost:39570 to xyz.xy.xyz.yz:5432 as root
**connected**
localPort: 53139
pid: 7478
tunnel established from localhost:53139 to xyz.xy.xyz.yz:5432 as root
**connected**
localPort: 56421
pid: 7479
tunnel established from localhost:56421 to xyz.xy.xyz.yz:5432 as root
**connected**
localPort: 5360
pid: 7480
tunnel established from localhost:5360 to xyz.xy.xyz.yz:5432 as root
**connected**
localPort: 40321
pid: 7481
tunnel established from localhost:40321 to xyz.xy.xyz.yz:5432 as root
*/