Automate Decisions with Execute Command and IF Logic
detail.loadingPreview
This workflow snippet demonstrates how to execute shell commands and leverage their output to make conditional decisions within your n8n automation. It's perfect for triggering actions based on dynamic data or system states.
About This Workflow
This n8n workflow snippet showcases a powerful combination of the 'Execute Command' and 'IF' nodes to build intelligent automations. The 'Execute Command' node allows you to run any shell command directly within your workflow, capturing its standard output. This output is then parsed by the 'To Flow Data' node, transforming it into a usable JSON object. The 'IF' node then dynamically evaluates a condition based on this parsed data. In this specific example, it checks if a value1 property within the command's output is true. If the condition is met, the workflow can proceed down a specific path, enabling sophisticated branching logic and decision-making based on external commands or data.
Key Features
- Execute Any Shell Command: Directly run shell commands from within your n8n workflows.
- Dynamic Data Parsing: Easily convert command output into structured JSON data.
- Conditional Workflow Branching: Implement decision points based on command results.
- Flexible Logic: Create complex automation flows that adapt to changing conditions.
How To Use
- Add the 'Execute Command' Node: Drag and drop an 'Execute Command' node onto your canvas.
- Configure the Command: In the node's parameters, enter the shell command you wish to execute (e.g.,
echo "{\"value1\": true, \"value2\": 1 }"). - Add the 'To Flow Data' Node: Connect the 'Execute Command' node's output to a 'To Flow Data' node.
- Set Function Code: In the 'To Flow Data' node, use the provided JavaScript function
item = JSON.parse(item.stdout); return item;to parse the command's output. - Add the 'IF' Node: Connect the 'To Flow Data' node's output to an 'IF' node.
- Define Conditions: Configure the 'IF' node to evaluate your desired condition. Use the expression editor to reference the parsed data from the previous node (e.g.,
={{JSON.parse($node["Execute Command"].data["stdout"]).value1}}). Set the comparison operator and the value to check against.
Apps Used
Workflow JSON
{
"id": "0f784e18-2843-4fbb-a051-c141d87bc4bf",
"name": "Automate Decisions with Execute Command and IF Logic",
"nodes": 19,
"category": "Operations",
"status": "active",
"version": "1.0.0"
}Note: This is a sample preview. The full workflow JSON contains node configurations, credentials placeholders, and execution logic.
Get This Workflow
ID: 0f784e18-2843...
About the Author
Free n8n Workflows Official
System Admin
The official repository for verified enterprise-grade workflows.
Statistics
Related Workflows
Discover more workflows you might like
Universal CSV to JSON API Converter
Effortlessly transform CSV data into structured JSON with this versatile n8n workflow. Integrate it into any application as a custom API endpoint, supporting various input methods including file uploads and raw text.
Instant WooCommerce Order Notifications via Telegram
When a new order is placed on your WooCommerce store, instantly receive detailed notifications directly to your Telegram chat. Stay on top of your e-commerce operations with real-time alerts, including order specifics and a direct link to view the order.
On-Demand Microsoft SQL Query Execution
This workflow allows you to manually trigger and execute any SQL query against your Microsoft SQL Server database. Perfect for ad-hoc data lookups, administrative tasks, or quick tests, giving you direct control over your database operations.