56 lines
1.3 KiB
JavaScript
56 lines
1.3 KiB
JavaScript
const { Client } = require('ssh2');
|
|
|
|
const config = {
|
|
host: 'hs.yifenbao.cn',
|
|
port: 22,
|
|
username: 'root',
|
|
password: 'Torch1112'
|
|
};
|
|
|
|
const conn = new Client();
|
|
|
|
conn.on('ready', async () => {
|
|
console.log('SSH连接成功');
|
|
|
|
try {
|
|
console.log('\n=== 查找Nginx配置文件 ===');
|
|
await executeCommand('ps aux | grep nginx');
|
|
|
|
console.log('\n=== 查找Nginx配置路径 ===');
|
|
await executeCommand('nginx -t 2>&1');
|
|
|
|
console.log('\n=== 查找Nginx安装位置 ===');
|
|
await executeCommand('which nginx');
|
|
|
|
console.log('\n=== 查找所有nginx配置文件 ===');
|
|
await executeCommand('find / -name "nginx.conf" 2>/dev/null');
|
|
|
|
} catch (error) {
|
|
console.error('检查失败:', error.message);
|
|
} finally {
|
|
conn.end();
|
|
}
|
|
});
|
|
|
|
function executeCommand(cmd) {
|
|
return new Promise((resolve) => {
|
|
conn.exec(cmd, (err, stream) => {
|
|
if (err) {
|
|
console.error('命令执行错误:', err.message);
|
|
resolve();
|
|
return;
|
|
}
|
|
|
|
stream.stdout.on('data', (data) => process.stdout.write(data));
|
|
stream.stderr.on('data', (data) => process.stdout.write(data));
|
|
|
|
stream.on('close', () => resolve());
|
|
});
|
|
});
|
|
}
|
|
|
|
conn.on('error', (err) => {
|
|
console.error('SSH连接错误:', err.message);
|
|
});
|
|
|
|
conn.connect(config); |