I would like to execute a script at logout with my GS7 android 9 (Resurrection Remix). I see that it is advised to use tasker. I guess it is possible to do that without installing a graphical application. I connect to the smartphone through adb and have a shell. Where can I write a file in the file system with bash or python commands that will be executed at logout ? Also, how should I manage the bash or python environment in order to have it working ? Thanks for your time.
Asked
Active
Viewed 212 times
1 Answers
4
On a rooted device you can make use of init
's on shutdown
trigger:
# /etc/init/custom.rc
on shutdown
exec - -- /path/to/executable
For more details on how to run an executable from init
's .rc
file, and what factors need to be taken care of, see my answer to How to run an executable on boot and keep it running?

Irfan Latif
- 20,353
- 3
- 70
- 213
shutdown.sh
script, make it executable and put it under/bin/
And it works from adb shell.
Then I created the
/etc/init/custom.rc
file withAnd when I shut it down that doesn't work. I think the files permissions are good. However, I am confused with the android file system. Should I make everything under
– yoarch Dec 20 '20 at 12:17/system
or not ?dos2unix
if needed. Start with something simple likeexec - -- /bin/echo Hello
. Then replace-
withu:r:magisk:s0
or some other super context. Or set SELinux permissive. Checkdmesg
forinit
log. – Irfan Latif Dec 22 '20 at 18:49