Skip to content

Tasker integration

ZestSSH works with Tasker through Android intents sent to its activity. From a Tasker task you can run a command, a snippet, a batch or a workflow, check that a host can be reached, or open a lasting session.

An intent runs without asking you first, unlike a zestssh:// link. That makes it the way to run automation with nobody at the phone. Because nobody is asked, ZestSSH signs in only with SSH keys you switched to Allow unattended runs (see Before you start).

  1. In ZestSSH, open More > Automation and turn on External automation (needs Squeezed).
  2. Tap API keys and create a key for Tasker (see API keys). Copy it when it is shown: ZestSSH shows a key only once.
  3. In Keys, open the key each host signs in with and turn on Allow unattended runs. Do the same for the keys of the host’s jump hosts.
  4. Connect to each host yourself once, so ZestSSH trusts its host key. A run with nobody there refuses a host key this device does not trust yet.
Intent action What it does
com.affluentlabs.zestssh.EXECUTE Runs a shell command
com.affluentlabs.zestssh.SNIPPET Runs a saved snippet
com.affluentlabs.zestssh.BATCH Runs a command on several hosts
com.affluentlabs.zestssh.WORKFLOW Runs a saved workflow
com.affluentlabs.zestssh.CONNECT Checks that a host can be reached: signs in, runs an echo, and disconnects
com.affluentlabs.zestssh.OPEN Opens a lasting session as a normal tab, so its port forwards set to start with the connection come up

Use OPEN, not CONNECT, when you want a host’s tunnels to come up. OPEN waits up to timeout seconds (default 30) for the session to connect before it answers.

  1. Open Tasker and create a new Task (or add an action to one you have).
  2. Add the action System > Send Intent.
  3. Set Action to one of the intent actions above.
  4. Set Target to Activity, and Package to com.affluentlabs.zestssh, so that no other app is offered the intent and its key.
  5. Add each extra in an Extra field of its own, as key:value. A value that Tasker sends as a number or as true or false is read just the same.
Extra Required Description
key Yes Your automation API key
connection_id Yes The host’s name (any letter case) or ID
command Yes The shell command to run
timeout No Seconds to wait (default 30, from 1 to 300)
grep No Keep only lines that match this pattern
head No Keep only the first N lines
tail No Keep only the last N lines
callback No HTTPS webhook address to POST the result to
Extra Required Description
key Yes Your automation API key
connection_id Yes The host’s name or ID
snippet_name Yes The saved snippet’s name (any letter case)
var_NAME No A value for the snippet’s {{NAME}} or ${NAME}

For a snippet that uses {{HOST}}, add the extra var_HOST:example.com. ZestSSH drops the var_ prefix and puts the value, shell-escaped, where {{HOST}} is.

Extra Required Description
key Yes Your automation API key
connections Yes Host names or IDs, separated by commas (connection_ids is taken too)
command Yes The shell command to run on every host
parallel No true (default) or false
timeout No Seconds to wait (default 30, from 1 to 300)
grep No Keep only matching lines
head No First N lines
tail No Last N lines
callback No HTTPS webhook address

With parallel on, at most 4 hosts run at once. A batch takes at most 25 hosts.

Extra Required Description
key Yes Your automation API key
workflow_name Yes* The saved workflow’s name (any letter case)
workflow_id Yes* The workflow’s ID

*Give workflow_name or workflow_id (or both).

Extra Required Description
key Yes Your automation API key
connection_id Yes The host’s name or ID
timeout No OPEN only: seconds to wait for the session (default 30)

When an app starts ZestSSH for a result with one of these intent actions, ZestSSH hands back two extras:

  • stdout: the command’s output after any filters, or the error message.
  • exit_code: for EXECUTE and SNIPPET, the command’s own exit code; for the other actions, 0 for success and 1 for failure.

The activity’s result is OK when the exit code is 0. An app that starts ZestSSH without asking for a result gets nothing back. Every run is in ZestSSH’s automation history either way.

When ZestSSH refuses a request, stdout starts with ERROR: and says why, for example ERROR: Automation is disabled in ZestSSH settings. With Encrypt data at rest on, a request that comes while ZestSSH is locked gets ERROR: ZestSSH is locked. Unlock it, then run this again. and exit code 1: its hosts and keys stay encrypted until you unlock it.

Task: Server Uptime Check
Action: Send Intent
Action: com.affluentlabs.zestssh.EXECUTE
Package: com.affluentlabs.zestssh
Target: Activity
Extra: key:YOUR_API_KEY
Extra: connection_id:web-01
Extra: command:uptime
Extra: timeout:15
Task: Deploy Staging
Action: Send Intent
Action: com.affluentlabs.zestssh.EXECUTE
Package: com.affluentlabs.zestssh
Target: Activity
Extra: key:YOUR_API_KEY
Extra: connection_id:staging-01
Extra: command:cd /var/www/app && git pull origin develop
Extra: timeout:60
Task: Fleet Disk Check
Action: Send Intent
Action: com.affluentlabs.zestssh.BATCH
Package: com.affluentlabs.zestssh
Target: Activity
Extra: key:YOUR_API_KEY
Extra: connections:web-01,web-02,web-03,db-01
Extra: command:df -h / | tail -1
Extra: parallel:true
Task: Restart Docker Container
Action: Send Intent
Action: com.affluentlabs.zestssh.SNIPPET
Package: com.affluentlabs.zestssh
Target: Activity
Extra: key:YOUR_API_KEY
Extra: connection_id:docker-01
Extra: snippet_name:Restart container
Extra: var_DOCKER:nginx-proxy
Task: Full Deploy
Action: Send Intent
Action: com.affluentlabs.zestssh.WORKFLOW
Package: com.affluentlabs.zestssh
Target: Activity
Extra: key:YOUR_API_KEY
Extra: workflow_name:Deploy staging
Task: Office Tunnels
Action: Send Intent
Action: com.affluentlabs.zestssh.OPEN
Package: com.affluentlabs.zestssh
Target: Activity
Extra: key:YOUR_API_KEY
Extra: connection_id:office-gateway

To test the intent path itself, send the intent with am start, each extra as a string:

Terminal window
adb shell am start -a com.affluentlabs.zestssh.EXECUTE \
-n com.affluentlabs.zestssh/.MainActivity \
--es key YOUR_API_KEY --es connection_id web-01 --es command uptime

The Automation wizard also gives an ADB command. That one opens the zestssh:// link instead, so ZestSSH shows Run this from a link? and waits for Run: it tests the link, not the intent.

Rather than writing the intent by hand, let the wizard build it:

  1. Open More > Automation > Automation wizard (shown while automation is on).
  2. Choose action: Execute command, Run snippet, Batch (multiple servers), Connect, or Run workflow.
  3. Pick the host or hosts, or the workflow.
  4. Configure the command, or the snippet and its variables, and the timeout.
  5. Optionally set Filters: Grep pattern, Head, Tail and Webhook URL.
  6. In Your automation, copy the Tasker intent card.

The card lists the action, the package, the target and each extra in Tasker’s key:value form. Where it says YOUR_KEY, paste your API key: “A key is shown only once, when it is made; if you did not keep yours, make a new one for this.” Make a new key for this makes a key there, shows it once, and puts it in the card until you close the wizard. A card that holds a key is a secret: treat it like a password. With no key at all, the wizard first asks for one (API key required, Generate API key).

  • Use Tasker profiles with time triggers for regular health checks.
  • Use the grep filter to keep only the lines you need from a long output.
  • Set a timeout that fits the command, so a slow command is not cut short.