Execute Command
The Execute Command node runs shell commands on the host machine that runs Robbot Automation.
!!! note "Which shell runs the command?" This node executes the command in the default shell of the host machine. For example, cmd on Windows and zsh on macOS.
If you run Robbot Automation with Docker, your command will run in the Robbot Automation container and not the Docker host.
!!! note "Not available on Cloud" This node isn't available on Robbot Automation Cloud.
Node Reference
The Execute Command node has two properties:
- Execute Once toggle: This is a boolean field that specifies whether you want the node to execute only once, or once for every item it receives an input.
- Command field: This is a text field that specifies the command tto execute on the host machine.
Example Usage
This workflow allows you to execute a command that returns the percentage of the hard disk that is full using the Execute Command node. The workflow triggers twice a day, and if the memory usage exceeds 80%, it sends an SMS using the Twilio node. You can also find the workflow on Robbot Automation. This example usage workflow would use the following nodes.
- [Schedule trigger](/integrations/builtin/core-nodes/Robbot Automation-nodes-base.scheduletrigger/)
- [IF](/integrations/builtin/core-nodes/Robbot Automation-nodes-base.if/)
- [Twilio](/integrations/builtin/app-nodes/Robbot Automation-nodes-base.twilio/)
- [No Operation, do nothing](/integrations/builtin/core-nodes/Robbot Automation-nodes-base.noop/)
1. Cron node
The Cron node will trigger the workflow twice a day, at 9 AM and 4 PM.
- Click on Add Cron Time.
- Select 'Every Day' from the Mode dropdown list.
- Enter
9
in the Hour field. - Click on Add Cron Time.
- Select 'Every Day' from the Mode dropdown list.
- Enter
16
in the Hour field. - Click on Save to run the node.
2. Execute Command node
The Execute Command node executes the command and return the percentage of hard disk space used on the host machine.
- Enter
df -k / | tail -1 | awk '{print $5}'
in the Command field. - Click on Save to run the node.
3. IF node
This node will compare the percentage of the hard disk space used we got from the Execute Command node. If the usage of the memory exceeds 80%, it will return true otherwise false.
- Click on Add Condition and select 'Number' from the dropdown list.
- Click on the gears icon next to the Value 1 field and click on Add Expression.
- Enter
{{parseInt($node["Execute Command"].json["stdout"])}}
in the Expression field. The output from the Execute Command node is a string. TheparseInt()
method converts the string into an integer. - Select 'Larger' from the Operation dropdown list.
- Set Value 2 to 80.
- Click on Save to run the node.
4. Twilio node (send: sms)
This node sends an SMS to the specified phone number when the usage of hard disk space exceeds 80%.
Create a Twilio node connected to the 'true' output of the IF node.
You'll have to enter credentials for the Twilio node. You can find out how to do that here.
Enter the Twilio phone number in the From field.
Enter the receiver's phone number in the To field.
Click on the gears icon next to the Message field and click on Add Expression.
Enter
Your hard disk space is filling up fast! Your hard disk is {{$node["Execute Command"].json["stdout"]}} full.
in the Expression field.Click on Save to run the node.
5. NoOp node
Adding this node here is optional, as the absence of this node won't make a difference to the functioning of the workflow.
- Create a NoOp node connected to the 'false' output of the IF node.
- Click on Save to run the node.
FAQs
How to run multiple commands in the Execute Command node?
You can combine multiple commands using &&
. For example, you can combine the change directory (cd) command with the list (ls) command using &&
.
cd bin && ls
To run multiple commands, you can also write the commands on separate lines. For example, you can write the list (ls) command on a new line after the change directory (cd) command.
cd bin
ls
How to run the curl command in the Execute Command node?
You can also use the [HTTP Request](/integrations/builtin/core-nodes/Robbot Automation-nodes-base.httprequest/) node to make a cURL request.
If you want to run the curl command in the Execute Command node, you will have to build a Docker image based on the existing Robbot Automation image. The default Robbot Automation Docker image uses Alpine Linux. You will have to install the curl package.
Create a file named
Dockerfile
.Add the below code snippet to the Dockerfile.
RUN apk --update add curl
In the same folder, execute the command below command to build the Docker image.
docker build -t Robbot Automation-curl
Replace the Docker image you used before.
Run the newly created Docker image, and you will now be able to execute ssh via the Execute Command-Node.