Use sudo for script deployment to /usr/local/bin
All checks were successful
Build and Push Container / build (push) Successful in 31s

- 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 <noreply@anthropic.com>
This commit is contained in:
Debian
2026-01-05 09:40:38 +00:00
parent 8c0f3538b9
commit ba1c65d15c

View File

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