steelbrain / node-ssh

SSH2 with Promises
MIT License
948 stars 94 forks source link

CommandExec seems not working for some reason... #411

Closed C0D3O closed 2 years ago

C0D3O commented 2 years ago

Hi, I want to copy a file to the server and run sudo systemctl restart prometheusd

here's the code

ssh.connect({ host: '75.119.142.169', port: '22', username: 'root', password: 'some password', privateKey: 'c:/Users/Administrator/.ssh/ssh_host_rsa_key_dima', }) .then(function () { // Local, Remote ssh.putFile('e:/Coding/autoGrafana/dima/prometheus.yml', '/prometheus/prometheus.yml').then( function () { console.log('Dima prometheus copied'); }, function (error) { console.log("Something's wrong"); console.log(error); } ); }) .then(function () { ssh.execCommand('sudo systemctl restart prometheusd', { cwd: '' }).then(function (result) { console.log('STDOUT: ' + result.stdout); console.log('STDERR: ' + result.stderr); }); });

and in the console I get blank STDOUT: STDERR: I guess they should not be empty right? anyways the command is not working, because I don't see any changes at where they should be:) what do I do wrong? Thank you

ps sorry I have no idea why it is formatting my code here............

C0D3O commented 2 years ago

everything is ok, my bad...