Tasker: continually check for shell command result and run task when it matches I've got the following shell command that checks to see if a particular process is running:

pgrep -x com.package.name


It either returns a process ID if the process is running, or it returns empty if it's not. How can I pop this into a tasker profile that checks every few seconds and runs a task when it sees that the result is empty?

The ultimate goal here is to keep near 100% uptime on a process that has a tendency to crash multiple times a day.
I see two ways to do what you want.

Run a time based profile and set it to repeat after every n minutes. Then follow your logical actions in the task of what to do when it crashes.

The other option (since the former doesn't give control on seconds but minutes and hours) is to execute the task manually or at some point automatically (say at 10:00 AM) but make an infinitely looping task.

For example, consider the following actions:

Note: Anything with and between &lt;&gt; has to be replaced with your custom values.


Code &rarr; Run Shell


Command: &lt;YOUR_COMMAND&gt;
Store Output In: %Grep

Create this action based on what to do when the above command returns nothing i.e. when the process is not running. 

When doing so, set an 'If' condition under that action. E.g. under the action  App &rarr; Launch App, the If condition would be %Grep Isn't Set. 

Note that I'm not talking about using a separate If action.
Add a wait of the amount of seconds/minutes/hours you want using Task &rarr; Wait
Now is the time to make an infinite loop. Use the action Task &rarr; Goto


Type: Action Number
Number: 1



All we've done here is to execute a command then execute an action if only the first command didn't yield anything, then wait for sometime and then repeat the whole procedure.

At some point, you would want to get rid of that infinite loop. You can either consider disabling and re-enabling Tasker or make a stop action in another task using Task &rarr; Stop, and execute it manually.