ssh_file_insert_lines_after_match
Insert lines after a specific line in a remote file via SSH. Useful for adding configuration directives or host entries after matching exact trimmed line content.
Instructions
Insert lines after a unique line match (ignoring leading/trailing whitespace).
PARAMETERS:
file_path: Path to the file to modify
match_line: Exact line content to match (whitespace-trimmed)
lines_to_insert: List of lines to insert after the match
To insert multiple lines: use ["first line", "second line", ...]
To insert a single line: use ["line to insert"]
To insert an empty line: use [""]
use_sudo: Use sudo for the operation (default: false)
force: Force operation even if file can't be read (sudo only) (default: false)
RETURNS: A dictionary with operation status including:
success: Boolean indicating if operation succeeded
file_path: Path to the modified file
EXAMPLES: Example 1: Insert configuration lines after a marker
{
"file_path": "/etc/nginx/nginx.conf",
"match_line": "http {",
"lines_to_insert": [" server_tokens off;", " client_max_body_size 20M;"]
}Example 2: Add a new host entry after localhost
{
"file_path": "/etc/hosts",
"match_line": "127.0.0.1 localhost",
"lines_to_insert": ["192.168.1.10 myserver.local"]
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | Path to the file to modify | |
| match_line | Yes | Exact line content to match | |
| lines_to_insert | Yes | Line(s) to insert after the match | |
| use_sudo | No | Use sudo for the operation | |
| force | No | Force operation even if file can't be read (sudo only) |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||