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).
Before you start
Section titled “Before you start”- In ZestSSH, open More > Automation and turn on External automation (needs Squeezed).
- Tap API keys and create a key for Tasker (see API keys). Copy it when it is shown: ZestSSH shows a key only once.
- 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.
- 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 actions
Section titled “Intent actions”| 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.
Setting up in Tasker
Section titled “Setting up in Tasker”- Open Tasker and create a new Task (or add an action to one you have).
- Add the action System > Send Intent.
- Set Action to one of the intent actions above.
- Set Target to Activity, and Package to
com.affluentlabs.zestssh, so that no other app is offered the intent and its key. - 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.
Intent extras
Section titled “Intent extras”EXECUTE
Section titled “EXECUTE”| 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 |
SNIPPET
Section titled “SNIPPET”| 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.
WORKFLOW
Section titled “WORKFLOW”| 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).
CONNECT and OPEN
Section titled “CONNECT and OPEN”| 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) |
Result return
Section titled “Result return”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,0for success and1for 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.
Examples
Section titled “Examples”Check a host’s uptime
Section titled “Check a host’s uptime”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:15Deploy with git pull
Section titled “Deploy with git pull”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:60Check disk usage on several hosts
Section titled “Check disk usage on several hosts”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:trueRun a snippet with a variable
Section titled “Run a snippet with a variable”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-proxyRun a workflow
Section titled “Run a workflow”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 stagingBring up a host’s tunnels
Section titled “Bring up a host’s tunnels”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-gatewayTesting from a computer with ADB
Section titled “Testing from a computer with ADB”To test the intent path itself, send the intent with am start, each extra as a string:
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 uptimeThe 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.
Using the Automation wizard
Section titled “Using the Automation wizard”Rather than writing the intent by hand, let the wizard build it:
- Open More > Automation > Automation wizard (shown while automation is on).
- Choose action: Execute command, Run snippet, Batch (multiple servers), Connect, or Run workflow.
- Pick the host or hosts, or the workflow.
- Configure the command, or the snippet and its variables, and the timeout.
- Optionally set Filters: Grep pattern, Head, Tail and Webhook URL.
- 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
grepfilter 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.