Invoke interactive shell?

26 views
Skip to first unread message

Soudane GMTA

unread,
Mar 26, 2023, 5:12:09 PM3/26/23
to Tasker
I'm using the latest Tasker beta on my Android 11 device.

Is there any way to get Tasker to invoke an interactive shell?  Unless I'm missing something, the Run Shell action seems to only run the command, capture its output, and then return to the Task which invoked it, and it cannot run commands interactively.

Suppose I wrote a command called /sdcard/command.sh which prompts the user for information and then runs one or more functions based upon what is input.  I would want to be able to tell Tasker to run it as follows:

/system/bin/sh /sdcard/command.sh

... and I would want a terminal window to open in which I can interact with that command in the same way that I would interact with it if I first did "adb shell" from my desktop computer and then performed the same command invocation.

Is there any way to do this in Tasker?

Thank you in advance.



Soudane GMTA

unread,
Mar 26, 2023, 7:59:07 PM3/26/23
to Tasker

I figured out a way:

I used the Termux plugin for Tasker.  I had to put the script into ~/.termux/tasker from Termux's point of view.
That's /data/data/com.termux/files/home/.termux/tasker  .

And I had to make make sure that /system/bin is in the path, and that the script has 755 permission.

Hmm ... actually, I can post the script here. It's a wrapper for the "cli" script that goes with the
LSPosed_mod utility (a new fork of LSPosed that enables its settings to be managed via the command
line, among other things that it enables, as well).

I hope that I don't mess up the markdown tags here, because Google groups doesn't offer a "preview"
function that I could use to verify what I entered ...

```
#!/system/bin/sh                                                                                                                                      

export PATH=/system/bin:${PATH}

/system/bin/clear

# This "cli" utility needs to run as root.                                                                                                
su=/system/bin/su
cli=/data/adb/lspd/bin/cli

while true
do
    echo
    ${su} - -c ${cli} -h
    read cmd?'                                                                                                                                        
>> ' rest
    case "${cmd}" in
    log|backup|modules|restore|scope|status)
        # Valid command.
        ;;
    ''|q|quit|exit)  # Line begins with an empty string in single quotes.
        # Quit.
        exit 0
        ;;
    *)
        # Invalid command. Just try again.
        continue
        ;;
    esac
    echo
    # Run the CLI command
    ${su} - -c ${cli} ${cmd} ${rest}
done

exit 0

```

I named the script lspd.sh, and I put it into /data/data/com.termux/files/home/.termux/tasker ,
and I set its perms to 755, as I described above.

When configuring the Termux plugin action in my Tasker action, I just specified lspd.sh as the
script to run, and I selected Execute in a terminal session.
Reply all
Reply to author
Forward
0 new messages