Initial commit
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { NodeSSH } from 'node-ssh';
|
||||
// Обратите внимание на .js в конце. Это обязательно для ESM!
|
||||
import { config } from './config.js';
|
||||
import type { ServerSettings } from './config.js';
|
||||
|
||||
const ssh = new NodeSSH();
|
||||
|
||||
async function processServer(server: ServerSettings) {
|
||||
console.log(`\n>>> Начинаю работу с сервером: ${server.host}:${server.port}`);
|
||||
|
||||
try {
|
||||
await ssh.connect({
|
||||
host: server.host,
|
||||
port: server.port,
|
||||
username: server.username,
|
||||
password: server.password
|
||||
});
|
||||
|
||||
console.log(`[${server.host}] Соединение установлено.`);
|
||||
|
||||
const commands = [
|
||||
'sudo apt-get update',
|
||||
'sudo DEBIAN_FRONTEND=noninteractive apt-get upgrade -y'
|
||||
];
|
||||
|
||||
for (const cmd of commands) {
|
||||
console.log(`[${server.host}] Выполняю: ${cmd}`);
|
||||
await ssh.execCommand(cmd, {
|
||||
onStdout(chunk) { process.stdout.write(chunk.toString()); },
|
||||
onStderr(chunk) { process.stderr.write(chunk.toString()); }
|
||||
});
|
||||
}
|
||||
console.log(`[${server.host}] ✅ Готово.`);
|
||||
} catch (error: any) {
|
||||
console.error(`[${server.host}] ❌ Ошибка: ${error.message}`);
|
||||
} finally {
|
||||
ssh.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
async function run() {
|
||||
for (const server of config) {
|
||||
await processServer(server);
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
||||
Reference in New Issue
Block a user