From ba1c65d15c2d46f4df05693df98e2d27ab388fc9 Mon Sep 17 00:00:00 2001 From: Debian Date: Mon, 5 Jan 2026 09:40:38 +0000 Subject: [PATCH] Use sudo for script deployment to /usr/local/bin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Use 'sudo tee' instead of redirect for writing scripts (redirects don't work with sudo) - Use 'sudo chmod' to make scripts executable - Cronjob still runs as user (no sudo needed) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- backend/services/monitors.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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",