Я пишу микросервис в Node.js, который запускает определенную операцию командной строки для получения определенной информации. Сервис работает на нескольких серверах, некоторые из них на Linux, некоторые на Windows. Я использую ssh2-exec
для подключения к серверам и выполнения команды, однако мне нужен способ определить ОС сервера для запуска правильной команды.
let ssh2Connect = require('ssh2-connect');
let ssh2Exec = require('ssh2-exec');
ssh2Connect(config, function(error, connection) {
let process = ssh2Exec({
cmd: '<CHANGE THE COMMAND BASED ON OS>',
ssh: connection
});
//using the results of process...
});
У меня есть идея для решения: после этот вопрос, заранее запустить какую-либо другую команду и определить ОС на основе вывода указанной команды; однако я хочу узнать, есть ли более «формальный» способ добиться этого, в частности, с использованием библиотеки SSH2
.