Shell scripts for Android | We discuss residents and other useful commands in everyday life.



Rep: (957)
Shell scripts for Android

The topic is devoted to the creation, debugging of scripts on the shell, as well as the development and study of various utilities command line Android.
For the full implementation of the desired under Android, as a rule, you will need root-rights and busybox.
This topic has grown from the topic.Tasker(parent theme), so don’t be surprised if you are suddenly sent there. (Tasker is a shell in Android.) From this topic has grown subsidiaryLinux kernel from the insideAll questions on the kernel should be asked in it.
Recipes, ideas, semi-ready examples.
Interception of hardware buttons, this script began with this script. It is recommended that you read the discussion.original postin the subjectTasker. Over the years, the script has found many different uses, seeMAX 3Tasker in the same topic, recipe "We catch events in logcat" here.
Modern lookto the button interception script: work on errors, performance evaluations, optimization.
Recipes withbusybox inotifyd
- Monitoring block devices(connect / disconnect flash drives and not only)
- Automate downloading files via torrent
- Spy on screenshots
Processing the status bar notificationaka Search in a file by a dynamically formed template from a pipe (pipe), recipes - in the discussion.
Recipes withservice call
- Read / write clipboardvia clipboard service [interfaceIClipboard]
- Mounting / Unmounting Disksvia mount service [interfaceIMountService]
- Enable USB MTPvia usb service [interfaceIusbmanager]
Search for service method numbers forservice call: with Taskertime, two; withusingJaDX (themeon the forum)
Reading contactsthrough contacts provider and utilitycontent
Showdowns with selinux
- More discussion selinux, which are key to understanding the work selinux in Android:
1 + discussion.Start, answerand away we go:note, comment, explanation, clarification, question, answer, end
2 + discussion.question, answer 1, answer 2, one more question, update 1, update 2, report, note, comment, end
- change selinux to support policiesnit.d: recipe itself, toolsandcomment.
We understand with the network routing in Android:Start...end.
We're setting up the network settings throughndc:
- general information onndc: Shell scripts for Android (Post Visitor7 # 58763900), Shell scripts for Android (Post username11 # 58769171)andScripts on the shell under Android (Post Visitor7 # 58784069)
- wifi access point control (tethering)Scripts on the shell under Android (Post kaztost # 58025052)
- installation of the dns server for the interfaceShell scripts for Android (Post Angel_Hranitel # 80575498)
RAM-Drive on Android (with continuation)
How to change init.rc (bottom message)
Tracking changes in a specific directory
Airplane mode (see and below)
Create a swap
We work with API VKontaktethroughcurl
Connect to a given Wi-Fi network
RTFM: materiel, regulatory documentation, literature
Bibliographyon Unix device, list item 1 is mandatory for reading
Shell programming (Unix)textbook A. Soloviev (seed - n. 1 of the above list - certainly preferable to paraphrase)
Help onbusybox
Android regulatory documents:
- Android Architectureaka Android Interfaces and Architecture - internal system device
- Android Core Technologies(Modern name - Configure an Android Device) - that can hack into the system and how to do it right
Hardware: "freezing" applications and components
- explanationon fingers
- discussion of the nuances:question, answer
- from obuzhdeniya above a couple of years there was a storyApplication freeze3 or many bukf
Hardware:character escaping
Shell scripting in the Android environmentXakep article in the magazine for those who are not able to master more or less serious text for sane people - a waste of time
Shell Developer Tools
teamset -x- the debugging tool built into the shell, displays each script command instderr, the details.
wShell- terminal emulator with web interface based on Shell In A Box. If the Android device and the computer are on the same local network, you can access the command line of the device from a computer via a web browser.
Shellcheck- static analyzer (lint) for shell scripts (few details)
Safety Rules. Read a must.
Most commands and scripts hosted in this thread are executed as root. This means that a command (or script), if used improperly, can create new problems and not help solve old ones. And the problems are already big, before which the old ones will seem to be a mere trifle.
Therefore, before you rush to download, drive commands and execute them
1. Make a full backup of the firmware (nandroid backup).
If you do not know what it is, you are in this topic too soon. Read the help sections for newbies on the forum, the theme of the firmware of your device.
"Toy" backups, such as Titanium Backup will not help, if something terrible happens. The backup manager bu built into Android ICS and higher (used by programs like Helium) will also not always help. Do not indulge and do not be lazy, make a normal backup from under the recovery.
2. Made in paragraph 1 backup put in a safe place.
Do not delete it immediately after your experiments have ended, in your opinion, successfully. Android can have a completely different view on their success. Watch the system, live some time in it. If you see strange things, roll back to the saved state. Watch again.
By the way, backup will help and analyze what happened, if something suddenly happens. We may need files from it during the trial.
3. If you don’t understand at all what a particular script does, laid out in the subject, still try to figure it out before you use it.
For some scripts it is necessary to comply with the conditions of their execution, otherwise they will not only not work, but also do something with the system. Easily.
Surely the script as it is laid out will not suit you. You will need to "finish" it to fit your needs.
Finally, the worst (and most unlikely, but still). You can slip a script that will do something bad. And okay, if you just poudalyaet files in the system, you also completed claim 1 of the Rules. (Really? Sure? Well, believe it.) Even worse, if the script sends something to a short number in Zimbabwe. Well, there is a credit card number, for example. What credit cards do not have? Nothing SMS to the short number in Zimbabwe is not free, you know. And do not think that anything you protect the script as root will not catch any anti-virus or various security managers. Of course, we quickly intervene and stop the further spread of malware. (But specifically your SMS is gone. In Zimbabwe.)
4. Your device (phone, tablet) is not the only testing ground for your experiences.
Most of the scripts can be checked and debugged on the BB under Linux. Virtual machine and Live distribution is enough. Any Linux distribution. It will take busybox to bring such a polygon closer to the real machine, but in any Linux distribution box, busybox is present.
You can also use the Android emulator. Yes, there is a Google on the farm and such. Lies next to the SDK for Android, an image with Android can be found on the Internet. This is anyway better than killing a real device. I remind you that it cost you a certain amount. (Of course, working in the emulator you are already tired of step 1 of the Rules. You do not need to follow these rules.)
5. For debugging scripts it is better to use not a terminal emulator application, but adb (Android Debug Bridge) or ssh session From BB to the device.
Fingers will break typing characters on the virtual keyboard. Again, make a mistake, make mischief. The client part of adb (for BB) can be found on the Internet, the server part in Android already exists (do not forget to enable debugging in “Settings”). Applications with ssh server can be found on Google Play.

There is no curator in the subject. If there is a user in the subject who wants to become a Curator and the correspondingRequirements for candidates, he can apply in the topicI want to be curator(after having studied the topic header and all materials for curators).
Prior to the appointment of the curator, on filling caps, please contactmoderatorssection through a buttonPictureunder the messages to which you want to add links.


Post has been editedderak1129 - 22.06.20, 23:05
Reason for editing: Notification.



Rep: (2511)
* Twaikyont 1. in the nucleus have no shielding, do yourself a binary / system / xbin / su \, work. And now this binary you do not have, so "No such file or directory". In general, script: # / path / interp args ~ / path / interp args script 2. Of course, this does not work rekaveri!. But you no rekaveri universal ways to find maps not think there is the necessary information is not available. Usually, universal way and not needed because rekaveri is highly dependent on the device. Actually, so scripts that you have posted in rekaveri do not need, it is easier and safer to use specific values, specific to this unit.

Post has been editedusername11 - 26.05.19, 14:27



Rep: (957)
In a hat

all, and that BRADA never fought with the lead. and certainly. inotifyd ? You could use here such strochechkoy ..
(Inotifyd - / mnt / sdcard / Pictures: w | while read event path name; do mkdir -p / dev / tasker; echo "$ name">/dev/tasker/shotname.txt; am broadcast -a net.dinglisch.android.tasker.ACTION_TASK -e task_name sshot; done) &

throw it somewhere and forget init.d. or Tasker start.
Kicked task Tasker 'sshot' - read the file /dev/tasker/shotname.txt, there is the file name of the screenshot threw a folder to the name - and do with the file we want. Yes it is possible, and the folder name to the stick was, so much so that's really written. (Echo "$ path $ name", and all).
The first letter there is what it means:
values ​​inotifyd codes
a File is accessed
c File is modified
e Metadata changed
w Writable file is closed
0 Unwritable file is closed
r File is opened
D File is deleted
M File is moved
u Backing fs is unmounted
o Event queue overflowed
x File can not be watched anymore


Post has been editedusername11 - 23.02.20, 15:50
Reason for edit: the post is placed in the cap



Rep: (824)
* coolkaas
Yes, everything from laziness probably :) busybox ls / storage / emulated / 0 / Pictures / Screenshots -ltr | tail -1 | awk '{print $ NF}' (tk question was subject Tasker, then monitored the change in the Screenshots Tasker), although initially proposes to solve through inotifyd (chroniclers Tasker threads will not lie)

Post has been editedmyxa781 - 09.08.14, 20:25



Rep: (2511)
* myxa781 , Another way: we know a file with the latest screenshots, store it in% LAST_FILE, further find<path>-newer% LAST_FILE.
But it also had to read, think ...

Post has been editedusername11 - 10.08.14, 12:36
Reason for editing: 00:00:02, 00:00:01, self-destruction activated ...



Rep: (750)
coolkaas Now it strikes me that Samsung makes scanning media content instead of using inotify



Rep: (2511)
* svs-57 And he uses it and - in Android has an interface to intotify (7). Or rather he did not, - Samsung - Google and the scanning is performed at the time of device connection, ie, when the fear that the files could fill via usb...

Post has been editedusername11 - 11.08.14, 18:48



Rep: (0)
Good day !
The most suitable topic for my question:
Is there a possibility of an external command to pause MP3 player (frozen?)?
And then "let go"?

I tried
pm disable
pm enable
no result.

For what I do - Navigator is used as an MP3 player, when power programm
Automate It disables all. But if you forget to pause the MP3 player, the device goes to sleep, and the day is discharged.



Rep: (824)
* alexalog,
input keyevent 85
input keyevent 86
If the player is not used for (e) tree

Post has been editedusername11 - 26.05.19, 14:32
Reason for editing: posts merged



Rep: (48)
Prompt how to make a file with the script allows zakonnektitsya telnet to another device and execute a few commands on it. Well, that is what should be the syntax of this file.



Rep: (750)
* Sesil b, telnet is problematic because the password is not entered. Can ssh?
eghttps: //play.google.co...=web.oss.sshsftpDaemon
/ Data / dropbear / ssh
Usage: / data / dropbear / ssh [options] [user @] host [/ port] [ [user @] host / port], ...] [command]

Post has been editedusername11 - 26.05.19, 14:37
Reason for editing: posts merged



Rep: (2511)
* Sesil b You can try the applet nc of busybox. But ssh is better.

Post has been editedusername11 - 26.05.19, 14:38



Rep: (442)
there is a script to backup your modem from the phone, and pouring it into a zip for rekaveri
#! / sbin / sh

# Backup partitions
dd if = / dev / block / platform / msm_sdcc.1 / by-name / m9kefs1 of = / data / local / tmp / m9kefs1.img;
dd if = / dev / block / platform / msm_sdcc.1 / by-name / m9kefs2 of = / data / local / tmp / m9kefs2.img;
dd if = / dev / block / platform / msm_sdcc.1 / by-name / m9kefs3 of = / data / local / tmp / m9kefs3.img;
dd if = / dev / block / platform / msm_sdcc.1 / by-name / fsg of = / data / local / tmp / fsg.img
dd if = / dev / block / platform / msm_sdcc.1 / by-name / eksst of = / data / local / tmp / eksst.img
dd if = / dev / block / platform / msm_sdcc.1 / by-name / modem of = / data / local / tmp / modem.img
dd if = / dev / block / platform / msm_sdcc.1 / by-name / modemst1 of = / data / local / tmp / modemst1.img
dd if = / dev / block / platform / msm_sdcc.1 / by-name / sns of = / data / local / tmp / sns.img
cd / data / local / tmp

# Creating zip file
/ System / xbin / zip zip -r -2 / sdcard / modem-sns-backup - $ (date +% y% m% y) .zip * .img / META-INF
But with them some sort of beard. From the terminal all like clockwork, and if the same script is run through the update script in rekaveri, does not even want to copy the modem to the phone and to pack even more.
log CWM
- Installing: /storage/sdcard1/efs-sns-backup.zip
Finding update package ...
I: Update location: /storage/sdcard1/efs-sns-backup.zip
Opening update package ...
Installing update ...
about to run program [/ sbin / busybox] with 3 args
about to run program [/ sbin / busybox] with 3 args
minzip: Extracted file "/ system / xbin / zip"
Modem and sns backup ...
minzip: Extracted file "/ data / local / tmp / META-INF / com / google / android / update-binary"
minzip: Extracted file "/ data / local / tmp / META-INF / com / google / android / updater-script"
about to run program [/tmp/backup.sh] with 1 args
1560 + 0 records in
1560 + 0 records out
798720 bytes (780.0KB) copied, 0.043030 seconds, 17.7MB / s
1560 + 0 records in
1560 + 0 records out
798720 bytes (780.0KB) copied, 0.038178 seconds, 20.0MB / s
1560 + 0 records in
1560 + 0 records out
798720 bytes (780.0KB) copied, 0.038909 seconds, 19.6MB / s
6144 + 0 records in
6144 + 0 records out
3145728 bytes (3.0MB) copied, 0.155182 seconds, 19.3MB / s
1024 + 0 records in
1024 + 0 records out
524288 bytes (512.0KB) copied, 0.027221 seconds, 18.4MB / s
131072 + 0 records in
131072 + 0 records out
67108864 bytes (64.0MB) copied, 7.615662 seconds, 8.4MB / s
6144 + 0 records in
6144 + 0 records out
3145728 bytes (3.0MB) copied, 0.155670 seconds, 19.3MB / s
16384 + 0 records in
16384 + 0 records out
8388608 bytes (8.0MB) copied, 0.414826 seconds, 19.3MB / s
zip warning: name not matched: /sdcard/modem-sns-backup-140914.zip
zip warning: name not matched: / META-INF
adding: eksst.img (deflated 100%)
adding: fsg.img (deflated 100%)
adding: m9kefs1.img (deflated 2%)
adding: m9kefs2.img (deflated 2%)
adding: m9kefs3.img (deflated 100%)
adding: modem.img (deflated 63%)
adding: modemst1.img (deflated 100%)
adding: sns.img (deflated 99%)
about to run program [/ sbin / busybox] with 3 args
script result was [0]

Install from sdcard complete.
I: Can not partition non-vfat: auto
the same garbage, does not create a zip at the root of the internal memory data, data mount through the updater-script
And yes, I SEE, and CWM.

Post has been editedusername11 - 26.05.19, 15:31
Reason for editing: posts merged



Rep: (750)
tiZwer @ 11.09.2014, 13:17*
/ System / xbin / zip zip -r -2 / sdcard / modem-sns-backup - $ (date +% y% m% y) .zip * .img / META-INF
Here sozdavetsya zip: / sdcard / name: modem-sns-backup - $ (date +% y% m% y) .zip
and the fact that further to the arguments - that the record in the zip
/ META-INF - eat, but there is no fundamentally
man zip
/ System / xbin / zip -r -2 / sdcard / modem-sns-backup - $ (date +% y% m% y) .zip * .img META-INF / *


Post has been editedusername11 - 26.05.19, 15:32
Reason for editing: posts merged



Rep: (957)
That's how music is played:
am start -a android.intent.action.VIEW -d file: ///mnt/sdcard/music/cuckooclock.mp3 -t audio / mp3
I checked.

Posted on 09/29/2014, 17:28:

and I Tasker notifies full charge. : - [



Rep: (836)
Again I go back to the parsing logcat. He does not go I even cry. For example, if I want to find the word SHAKE perform an action (in my case audio).
10-21 12: 46: 33.036 D / GravityService (2644): keeper SHAKE event

logcat -c; script -q -c 'logcat -s GravityService: D' / dev / null | awk '/ SHAKE / {system ( "am broadcast -a net.dinglisch.android.tasker.ACTION_TASK -e task_name Beep")};' 1>/ dev / null &

Sample through a plug Tasker SS
task
Log_script (138)
A1: Secure Settings [Configuration: logcat_beep (Root) Package: com.intangibleobject.securesettings.plugin Name: Secure Settings Timeout (Seconds): 0]

And he successfully hangs in the status bar, but it does not work on SHAKE.
Without logkata and AVK team worked through.
Kind of like awk and system are not compatible.

It earned only through myxa781 and had to abandon the awk
logcat -c; script -q -c / dev / null | while read code; do echo "$ code" | grep -q 'GravityService *: keeper SHAKE event.' && am broadcast -a net.dinglisch.android.tasker.ACTION_TASK -e task_name Beep; done
That only worked on SHAKE necessary instead keeper SHAKE event - * SHAKE *

Post has been editedsergr59 - 23.10.14, 16:41
Reason for editing: Updated



Rep: (824)
* sergr59,
you throw the SS, in Tasker script->run shell

logcat -c; script -q -c 'logcat -s GravityServic e: D '/ dev / null | awk '/ SHAKE / {system ( "am broadcast -a net.dinglisch.android.tasker.ACTION_TASK -e task_name Beep")};'>/ dev / null &

Post has been editedmyxa781 - 21.10.14, 19:24



Rep: (2511)
* sergr59 , Well, not for nothing that in the header output from logcat selected through while read. And you thought "some bydlokodery written right now, I'll write correctly." : D Of course, we are still those programmers, but there is not read nothing worth - is virtually the only way to overcome the buffering in Android in the channel.



Rep: (905)
Greetings .. Mot thread who came across as using service call to turn off WiFi and APN ..? The source code Nitsche not found to disable .. Not found airplane mode (disables all) - but it is not ..
Enabling works ..
service call connectivity 61 s16 android.net.IConnectivityManager. - to include flight
service call connectivity 22 s16 android.net.IConnectivityManager - enable APN
service call wifi 13 s16 android.net.IWifiManager - turn on WiFi
PS. Sources 4.4.2 look ..

Post has been editedusername11 - 26.05.19, 17:11
Reason for editing: posts merged



Rep: (2511)
* Axell Refer to the source again, see IConnectivityManager.setMobileDataEnabled (boolean enabled)? Those. parameter is passed to it. Same with the wifi, but it can be controlled and through svc.

Post has been editedusername11 - 26.05.19, 17:12



Rep: (957)
good article on the hacker about our business.
http://xakep.ru/android-shell-script/


Full version    

Help     rules

Time is now: 09/09/20, 2:19