Command Demo

Execute commands

Command Demo

AI-generated

Overview

This node executes a shell command on the system where n8n is running and returns the output of that command. It is useful for scenarios where you want to run arbitrary system commands or scripts as part of your workflow, such as retrieving system information, managing files, or invoking other command-line utilities.

For example, you could use this node to:

  • Get the current user by running whoami.
  • List files in a directory using ls -l.
  • Check system uptime with uptime.

Because it runs commands directly on the host machine, it should be used carefully to avoid security risks.

Properties

Name Meaning
Command The shell command to execute. Examples: whoami, ls -l, uptime

Output

The node outputs a single JSON object with one field:

  • output: A string containing the standard output of the executed shell command.

Example output JSON:

{
  "output": "username\n"
}

No binary data is produced by this node.

Dependencies

  • Requires Node.js child_process module to execute shell commands.
  • Runs commands on the local system where n8n is hosted; no external API dependencies.
  • No special environment variables or credentials are needed, but appropriate permissions to execute shell commands on the host are required.

Troubleshooting

  • Common issues:

    • Command not found or invalid command syntax will cause the node to throw an error.
    • Insufficient permissions to execute certain commands may result in permission denied errors.
    • Running potentially dangerous commands can compromise system security; ensure only trusted commands are used.
  • Error messages:

    • Errors from the underlying shell command execution will be propagated. For example, if the command is invalid, you might see an error indicating "command not found".
    • To resolve, verify the command syntax and ensure the n8n process has necessary permissions.

Links and References

Discussion