39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
import subprocess
|
|
|
|
# Transfer the script to VPS
|
|
with open(r'c:\Projects\metallkart-erp\scripts\test-m2b-weekly-report.ts', 'rb') as f:
|
|
data = f.read()
|
|
|
|
proc = subprocess.Popen(
|
|
['ssh', 'root@76.13.55.81', 'cat > /opt/erp/metallkart-erp/scripts/test-m2b-weekly-report.ts'],
|
|
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
|
)
|
|
_, err = proc.communicate(input=data)
|
|
if proc.returncode != 0:
|
|
print(f'Transfer failed: {err.decode()}')
|
|
exit(1)
|
|
print('Script transferred to VPS')
|
|
|
|
# Run on VPS
|
|
cmd = (
|
|
'cd /opt/erp/metallkart-erp && '
|
|
'ADMIN_PASSWORD="MetallKart2026!" '
|
|
'API_BASE_URL=http://localhost:3001 '
|
|
'npx tsx scripts/test-m2b-weekly-report.ts 2>&1'
|
|
)
|
|
|
|
proc = subprocess.Popen(
|
|
['ssh', 'root@76.13.55.81', cmd],
|
|
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
|
)
|
|
out, err = proc.communicate(timeout=300)
|
|
|
|
with open(r'c:\Projects\metallkart-erp\tmp_m2b_output.txt', 'wb') as f:
|
|
f.write(out)
|
|
if err:
|
|
f.write(b'\n--- STDERR ---\n')
|
|
f.write(err)
|
|
|
|
print(f'Done. Output length: {len(out)} bytes')
|
|
print(out.decode('utf-8', 'replace'))
|