Skip to content

Execute Command#

The Execute Command node runs shell commands on the host machine that runs Ensemble.

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 Ensemble with Docker, your command will run in the Ensemble container and not the Docker host.

Not available on Cloud

This node isn't available on Ensemble 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 Pathway allows you to execute a command that returns the percentage of the hard disk that is full using the Execute Command node. The Pathway triggers twice a day, and if the memory usage exceeds 80%, it sends an SMS using the Twilio node. This example usage Pathway would use the following nodes.

1. Cron node#

The Cron node will trigger the Pathway 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 Execute Node 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 Execute Node to run the node.

The node executes the command and returns the percentage of the hard disk that is full.

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 Execute Node to run the node.

The node returns an output when the percentage of hard disk space used exceeds 80%.

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 Execute Node to run the node.

The node sends an SMS with the percentage of the hard disk space used that you got from the Execute Command 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 Execute Node 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 &&.

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

1
2
cd bin
ls

How to run the curl command in the Execute Command node?#

You can also use the HTTP Request 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 Ensemble image. The default Ensemble 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.

    1
    2
    FROM docker.Ensemble.io/Ensembleio/ensemble
    RUN apk --update add curl
    
  3. In the same folder, execute the command below command to build the Docker image.

    1
    docker build -t Ensemble-curl
    
  4. Replace the Docker image you used before. For example, replace docker.Ensemble.io/Ensembleio/ensemble with Ensemble-curl.

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