const { Client } = require('ssh2');
const conn = new Client();
function exec(conn, cmd) {
  return new Promise((resolve, reject) => {
    conn.exec(cmd, (err, stream) => {
      if (err) return reject(err);
      let out = '', e = '';
      stream.on('data', d => out += d);
      stream.stderr.on('data', d => e += d);
      stream.on('close', () => resolve({ out: out.trim(), err: e.trim() }));
    });
  });
}
conn.on('ready', async () => {
  const r1 = await exec(conn, 'grep -n "terrain" /home/slin/enduro-trails/prototype/static/app.js | head -20');
  console.log('app.js terrain refs:', r1.out || '(none)');

  const r2 = await exec(conn, 'grep -n "terrain" /home/slin/enduro-trails/prototype/static/index.html | head -20');
  console.log('index.html terrain refs:', r2.out || '(none)');

  const r3 = await exec(conn, 'grep -n "terrain" /home/slin/enduro-trails/prototype/static/app.css | head -10');
  console.log('app.css terrain refs:', r3.out || '(none)');

  conn.end();
});
conn.on('error', err => { console.error('error:', err.message); process.exit(1); });
conn.connect({ host: '82.22.50.71', username: 'slin', password: 'motoZ@yaz2010', readyTimeout: 15000 });
