collectLog.js 881 B

1234567891011121314151617181920212223242526272829
  1. const node_ssh = require('node-ssh');
  2. const config = require('./config');
  3. const path = require('path');
  4. const fs = require('fs');
  5. config.servers.forEach((host, index) => {
  6. console.log(host);
  7. let ssh = new node_ssh();
  8. ssh.connect({
  9. host: host,
  10. username: 'root',
  11. port: 22,
  12. password: config.password,
  13. }).then(async function() {
  14. ssh.getFile(path.resolve(__dirname, `server-${index}.log`), '/root/autoTrade/autoTrade.log')
  15. .then(
  16. function(Contents) {
  17. console.log("The File's contents were successfully downloaded");
  18. },
  19. function(error) {
  20. console.log("Something's wrong");
  21. console.log(error);
  22. },
  23. )
  24. .then(() => {
  25. ssh.dispose();
  26. });
  27. });
  28. });