termux / termux/termux-api

termux-location sometimes returns no output when ran in crontab

Open
#719 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
4.3k
Forks
920
PR merge metrics
No merged PRs in 30d

Description

Problem description

When running script via crontab, it sometimes writes empty files, even with retries. When running via bash while being at the same geolocation, it writes a file as expected.

Script save-location.sh:

retries=5
path="$HOME/location"
filename=$(date +'%Y-%m-%d_%H-%M-%S').json
fullpath="$path/$filename"

touch "$fullpath"

while [[ ! -s "$fullpath" && "$retries" -ne 0 ]]; do
  termux-location > "$fullpath"
  ((retries--))
done

When executed via bash save-location.sh, it writes the termux location to the file.

When running as a crontab job

*/1 * * * * bash ~/git/linux/android/save-location/save-location.sh 

then some of the files are empty, some are populated.

Steps to reproduce

pkg in cronie
mkdir ~/location
crontab -e
# edit in editor
*/1 * * * * bash <full path to save-location.sh>
# it will run every 1 minute
# save

Look into ~/location. Some of the files will be empty, some will contain the location json.

Expected behavior

All files contain termux location json.

Additional information

Termux Variables:
TERMUX_API_VERSION=0.50.1
TERMUX_APK_RELEASE=F_DROID
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP_PID=17942
TERMUX_IS_DEBUGGABLE_BUILD=0
TERMUX_MAIN_PACKAGE_FORMAT=debian
TERMUX_VERSION=0.118.1
TERMUX__USER_ID=0
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://mirror.quantum5.ca/termux/termux-main stable main
Updatable packages:
c-ares/stable 1.34.1 aarch64 [upgradable from: 1.33.1]
glib/stable 2.80.5-2 aarch64 [upgradable from: 2.80.5-1]
tree-sitter/stable 0.24.3 aarch64 [upgradable from: 0.24.2]
termux-tools version:
1.43.6
Android version:
14
Kernel build information:
Linux localhost 6.1.43-android14-11 #1 SMP PREEMPT Mon Aug 26 02:08:56 UTC 2024 aarch64 Android
Device manufacturer:
samsung
Device model:
SM-A556B
LD Variables:
LD_LIBRARY_PATH=
LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so
Installed termux plugins:
com.termux.window versionCode:15
com.termux.widget versionCode:13
com.termux.nix versionCode:188036
com.termux.styling versionCode:1000
com.termux.api versionCode:51
com.termux.boot versionCode:1000

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the save-location.sh script and reproduce the */1 * * * * crontab entry using cronie, comparing scheduled and interactive runs of termux-location. Inspect why scheduled invocations sometimes produce empty files; done means establishing a reliable output or documenting the confirmed limitation and its conditions.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, shell
Domain
cli, mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.