init: workspace opencode sync
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import paramiko
|
||||
import time
|
||||
|
||||
client = paramiko.SSHClient()
|
||||
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
client.connect('192.168.100.2', username='mi4', password='m14', look_for_keys=False, allow_agent=False)
|
||||
|
||||
def run(cmd, wait=1.0):
|
||||
time.sleep(wait)
|
||||
stdin, stdout, stderr = client.exec_command(cmd)
|
||||
time.sleep(1.0)
|
||||
out = stdout.read().decode().strip()
|
||||
err = stderr.read().decode().strip()
|
||||
if err:
|
||||
print(f" ERR: {err[:200]}")
|
||||
return out
|
||||
|
||||
def esc_for_routeros(s):
|
||||
return s.replace('"', '\\"').replace('$', '\\$').replace('\\', '\\\\')
|
||||
|
||||
# Test: simple script creation via exec_command
|
||||
print("=== Test: script create via exec_command ===")
|
||||
test_code = ':put "test123"'
|
||||
esc_test = esc_for_routeros(test_code)
|
||||
print(f"Escaped: {esc_test}")
|
||||
|
||||
result = run(f'/system script add name=test_esc source="{esc_test}"')
|
||||
print(f"Create result: '{result}'")
|
||||
|
||||
result = run(':put [/system script get test_esc source]')
|
||||
print(f"Stored source: '{result}'")
|
||||
|
||||
run('/system script remove test_esc')
|
||||
print()
|
||||
|
||||
if 'test123' not in result:
|
||||
print("Script creation NOT working! Debugging further...")
|
||||
# Try a simpler approach: no special chars at all
|
||||
result2 = run('/system script add name=test2 source=":put hello"')
|
||||
print(f"Simple create: '{result2}'")
|
||||
result2 = run(':put [/system script get test2 source]')
|
||||
print(f"Simple source: '{result2}'")
|
||||
run('/system script remove test2')
|
||||
|
||||
# Try without quotes
|
||||
result3 = run('/system script add name=test3 source="hello"')
|
||||
print(f"Min create: '{result3}'")
|
||||
result3 = run(':put [/system script get test3 source]')
|
||||
print(f"Min source: '{result3}'")
|
||||
run('/system script remove test3')
|
||||
|
||||
# Try with just a dollar sign
|
||||
result4 = run('/system script add name=test4 source=":put \\$x"')
|
||||
print(f"$ create: '{result4}'")
|
||||
result4 = run(':put [/system script get test4 source]')
|
||||
print(f"$ source: '{result4}'")
|
||||
run('/system script remove test4')
|
||||
|
||||
client.close()
|
||||
Reference in New Issue
Block a user