diff --git a/backend/services/monitors.py b/backend/services/monitors.py index d0dcc22..37fc2f0 100644 --- a/backend/services/monitors.py +++ b/backend/services/monitors.py @@ -278,10 +278,9 @@ class MonitorService: "error": f"Could not connect to {hostname}", } - # Write the script to the remote host using heredoc - # Escape any single quotes in the script content - escaped_content = script_content.replace("'", "'\"'\"'") - write_cmd = f"cat > {script_path} << 'KUMA_SCRIPT_EOF'\n{script_content}KUMA_SCRIPT_EOF" + # Write the script to the remote host using sudo tee (works for non-root users) + # Using tee instead of redirect because sudo doesn't apply to redirects + write_cmd = f"sudo tee {script_path} > /dev/null << 'KUMA_SCRIPT_EOF'\n{script_content}KUMA_SCRIPT_EOF" result = ssh.execute(hostname, write_cmd, username, port) if not result.success: return { @@ -290,7 +289,7 @@ class MonitorService: } # Make the script executable - chmod_result = ssh.execute(hostname, f"chmod +x {script_path}", username, port) + chmod_result = ssh.execute(hostname, f"sudo chmod +x {script_path}", username, port) if not chmod_result.success: return { "status": "failed",