72 lines
2.3 KiB
JavaScript
72 lines
2.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', () => {
|
|
console.log('SSH连接成功');
|
|
|
|
console.log('1. 复制文件到容器...');
|
|
conn.exec('docker cp /tmp/huishou-h5/. huishou:/usr/share/nginx/html/h5/', (err, stream) => {
|
|
if (err) {
|
|
console.error('docker cp失败:', err.message);
|
|
conn.end();
|
|
return;
|
|
}
|
|
|
|
stream.on('close', () => {
|
|
console.log(' ✓ 文件已复制到容器');
|
|
|
|
console.log('2. 验证容器内文件...');
|
|
conn.exec('docker exec huishou ls -la /usr/share/nginx/html/h5/assets/', (err, stream) => {
|
|
if (err) {
|
|
console.error('检查容器失败:', err.message);
|
|
conn.end();
|
|
return;
|
|
}
|
|
|
|
let output = '';
|
|
stream.stdout.on('data', (data) => {
|
|
output += data.toString();
|
|
});
|
|
|
|
stream.on('close', () => {
|
|
console.log('容器内assets目录:');
|
|
console.log(output);
|
|
|
|
console.log('3. 验证称重页面...');
|
|
conn.exec('docker exec huishou grep -c "inputMode" /usr/share/nginx/html/h5/assets/pages-weigh-*.js', (err, stream) => {
|
|
let countOutput = '';
|
|
stream.stdout.on('data', data => countOutput += data);
|
|
stream.on('close', () => {
|
|
console.log('inputMode出现次数:', countOutput.trim());
|
|
|
|
console.log('4. 检查默认模式...');
|
|
conn.exec('docker exec huishou grep -o "inputMode.*manual\\|manual.*inputMode" /usr/share/nginx/html/h5/assets/pages-weigh-*.js | head -3', (err, stream) => {
|
|
let result = '';
|
|
stream.stdout.on('data', data => result += data);
|
|
stream.on('close', () => {
|
|
console.log('搜索结果:', result);
|
|
console.log(result ? '✓ 默认模式已设为manual' : '✗ 默认模式未设为manual');
|
|
conn.end();
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
conn.on('error', (err) => {
|
|
console.error('SSH连接错误:', err.message);
|
|
});
|
|
|
|
conn.connect(config); |