Skip to main content

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:

  1. 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.
  2. 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.

  1. Click on Add Cron Time.
  2. Select 'Every Day' from the Mode dropdown list.
  3. Enter 9 in the Hour field.
  4. Click on Add Cron Time.
  5. Select 'Every Day' from the Mode dropdown list.
  6. Enter 16 in the Hour field.
  7. 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.

  1. Enter df -k / | tail -1 | awk '{print $5}' in the Command field.
  2. 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.

  1. Click on Add Condition and select 'Number' from the dropdown list.
  2. Click on the gears icon next to the Value 1 field and click on Add Expression.
  3. Enter {{parseInt($node["Execute Command"].json["stdout"])}} in the Expression field. The output from the Execute Command node is a string. The parseInt() method converts the string into an integer.
  4. Select 'Larger' from the Operation dropdown list.
  5. Set Value 2 to 80.
  6. 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%.

  1. Create a Twilio node connected to the 'true' output of the IF node.

  2. You'll have to enter credentials for the Twilio node. You can find out how to do that here.

  3. Enter the Twilio phone number in the From field.

  4. Enter the receiver's phone number in the To field.

  5. Click on the gears icon next to the Message field and click on Add Expression.

  6. Enter Your hard disk space is filling up fast! Your hard disk is {{$node["Execute Command"].json["stdout"]}} full. in the Expression field.

  7. 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.

  1. Create a NoOp node connected to the 'false' output of the IF node.
  2. 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.

  1. Create a file named Dockerfile.

  2. Add the below code snippet to the Dockerfile.

    RUN apk --update add curl
  3. In the same folder, execute the command below command to build the Docker image.

    docker build -t Robbot Automation-curl
  4. Replace the Docker image you used before.

  5. Run the newly created Docker image, and you will now be able to execute ssh via the Execute Command-Node.