Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Termux scripts crash when launched from Tasker/Llama (Android 8) #464

Closed
txoof opened this issue Nov 1, 2017 · 9 comments
Closed

Termux scripts crash when launched from Tasker/Llama (Android 8) #464

txoof opened this issue Nov 1, 2017 · 9 comments

Comments

@txoof
Copy link

txoof commented Nov 1, 2017

ISSUE:
Scripts in the ~/.termux/tasker path launch from Tasker or Llama can be launched and work properly most of the time. Occasionally a job crashes when launched from Tasker or Llama. When the job crashes, the job will not run again from Tasker or Llama until the job is edited via the Termux:Task interface; this does not always work. The script can always be run through a terminal/ssh session without issue.

Crash Information (is there a better way to get this information other than manually typing it in?):
Stack Trace (as much as I could bare to type in):
java.lang.Runtime.Exception: Unable to start receiver com.termux.tasker.FireReciver: java.lang.IllegalStateException: Not allowed to start service intent { act=com.termux.service_execute dat=com.termux.file:/data/data/com.termux/files/home/.termux/tasker/rsync_nprpodcast-lan cmp=com.termux/app.TermuxService(has extras): app is in background uid UidRecord(e17e965 u0a187 RCVR bg+4m34s924ms idle procs:3 seq(424,424,424)}

Android Information:
Termux version:
<=0.48
Installed Termux apps:
Updatable packages:
All packages up to date
System information:
Linux localhost 3.18.52-g99dda0323132 #1 SMP PREEMPT Fri Aug 18 00:56:04 UTC 2017 aarch64 Android
Termux-packages arch:
aarch64
Android version:
8.0.0
Device manufacturer:
Google
Device model:
Pixel

@txoof
Copy link
Author

txoof commented Nov 1, 2017

I'm still gathering information on this, but it appears that since Termux was upgraded, symbolic links that point to relative paths could be causing this issue.

The scripts related to this issue are kept in /data/data/com.termux/files/home/scripts with a symbolic link in $HOME/.termux/tasker pointing to ~/scripts/SCRIPT_NAME instead of the full path.

Removing the relative path (~/) and replacing it with /data/data/com.termux/files/home/scripts appears to have solved this issue.

I don't think this is closed as the issue is very unpredictable. The job can work fine for several hours and then suddenly crash, requiring the editing step mentioned above.

@fornwall
Copy link
Member

fornwall commented Nov 2, 2017

Thanks for reporting!

Can you check if the just released version 0.3 of Termux:Tasker fixes the issue? It should be available as an update from Google Play within a few hours max (and from F-Droid within a day or two).

@fornwall fornwall closed this as completed Dec 7, 2017
@tukusejssirs
Copy link

I have a similar problem. I created a script, placed it in ~/.termux/tasker, made it executable, created a new task in Tasker (for debugging, I execute it in a terminal session). However, when execute it, here’s the output:

e[95mChecking Open GApps configuration and version ...\e[39m
/data/data/com.termux/files/home/.termux/tasker/ogus.sh: 25: [[: gapps: unexpected operator
-e \e[91mERROR: This script only updates Open GApps. On current system, the Open GApps are not installed.\e[39m

[Process completed (code 2) - press Enter]

The problem lays in this line:

/data/data/com.termux/files/home/.termux/tasker/ogus.sh: 25: [[: gapps: unexpected operator

On the particular line, there is an if. I tried to use [ and also [[, but I could not make it work. I looks like it does not load bash shell and installed programs (like coreutils).

I even changed shebang from #!/bin/bash to #!/data/data/com.termux/files/usr/bin/bash, no change.

Current version of the script can be found here.

I use latest app versions of Termux, Termux-tasker, Tasker installed from Google Play and all my packages are updated.

@Grimler91
Copy link
Member

@tukusejssirs you can get rid if the [[ error with "$type" instead of $type. That won't fix the second error though. Your device probably doesn't have the /system/etc/g.prop file

@tukusejssirs
Copy link

tukusejssirs commented Feb 2, 2019

(1) Quoting variable does not work. Which is expected by me, because shell keyword [[ and shell builtin are not available and this is the reason for the first and main error.

(2) The scripts works as expected when running directly from Termux.

(3) It is a script created by me. I want to create a sort of cronjob on Android using the Tasker.

(4) The second error is a result of non-available programs. I use grep and sedin variable definition of $type, therefore the error.

============

The expected solution: availability of all installed programs.

@ghost
Copy link

ghost commented Feb 2, 2019

  1. Why shebang is on line 16 ? https://github.com/tukusejssirs/lnx_scripts/blob/master/bash_functions/termux/ogus.sh#L16

  2. Error happens only when script is executed with "dash" (sh). It is executed with dash because of (1). Shebang should be only on first line and not somewhere in the middle of file. Just assume that shebang is a file type signature.

Info, how Termux distinguish binaries and scripts: https://github.com/termux/termux-app/blob/master/app/src/main/java/com/termux/app/BackgroundJob.java#L138-L183 - as in (2), shebang is read at the first line.

@tukusejssirs
Copy link

@xeffyr is right. In Termux, the shebang must be on the first line.

To answer your question: I am accustomed to have all general comments written at the beginning of the scripts before the shebang.

I never had this experience / these issues on (desktop) Linux, therefore I presumed the same behaviour on Termux, too. I see I was wrong.

Now I know that I can leave the shebang as #!/bin/bash, as Termux automatically changes it to #!$PREFIX/bin/bash.

Thank you! :)

@ghost
Copy link

ghost commented Feb 2, 2019

I presumed the same behaviour on Termux, too. I see I was wrong.

When you use shell (like bash) in interactive mode, you can omit shebangs at all. In this case scripts will be executed with your current shell. (in that case you are not wrong)

Plugins like Termux:Tasker ask Termux to execute file manually. To support many script types, Termux read the first line of file and determines the right interpreter to execute it. So here shebangs should always exist on the first line of scripts.

@tukusejssirs
Copy link

I thought it should do it this way: search first non-blank and non-comment line.

@ghost ghost locked and limited conversation to collaborators Oct 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants