369 pagesV  < 1 2 3 4 5 6 > »  
 
REPLY
> Shell scripts for Android | We discuss residents and other useful commands in everyday life.
coolkaas
Message#1
14.10.13, 17:04
viewer
*********
[offline]

Group: Friendssavagemessiahzine.com
Messages 5952
Check in: 09.11.10
Xiaomi Redmi 4X 3/32

Reputation:-  849  +

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 3in the subjectTasker, recipe "We catch events in logcat" here.
Modern lookto the button interception script: work on errors, performance evaluations, optimization.
Recipes with busybox 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.
Service call recipes
- Read / write clipboardvia clipboard service [iClipboard interface]
- Mounting / Unmounting Disksthrough the mount service [IMountService interface]
- Enable USB MTPvia usb service [IUsbManager interface]
Search for service call service method numbers: with Taskertime, two; withusingJaDX (themeon the forum)
Reading contactsthrough the contacts provider and the content utility
Showdowns with selinux
- a great discussion about selinux,Shell scripts for Android (Post kaztost # 57413273)- almost the very beginning of the discussion,Scripts on the shell under Android (Post kaztost # 59209740)- almost the end, this discussion is key to understanding the work of selinux in Android
- change selinux policies to support init.dScripts on the shell under Android (Fast kaztost # 60897799)andShell scripts for Android (Post kaztost # 60899182)
Disable network settings via ndc
- general information on ndc:Scripts on the shell under Android (Post username11 # 57827452) Scripts on the shell under Android (Post Visitor7 # 58734414)andScripts on the shell under Android (Post Visitor7 # 58784069)
- installation of the dns server for the interfaceScripts on the shell under Android (Post kaztost # 57873002)
- wifi access point control (tethering)Scripts on the shell under Android (Post kaztost # 58025052)
Fstab Android flags for Marshmallow
RAM Disk on Android? Easy! (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 VKontakte (+ curl)
Connect to a given Wi-Fi network
RTFM: materiel, regulatory documentation, literature
Busybox help
Online man pages (Picturethankvitaly51370)
Shell programming (Unix)study guide A. Solovyov
Hardware: "freezing" applications and components
- explanationon fingers
- discussion of the nuances:question, Start, answerlong discussionanswer
Hardware:character escaping
Android regulatory documents:
- Android Interfaces and Architecture- the internal structure of the system
- Android Core Technologies- what can be hacked in the system, and how to do it correctly
Bibliographyon Unix device, list item 1 is mandatory for reading
Shell scripting in the Android environmentXakep magazine article
Shell Developer Tools
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)
Mini application for displaying dialog boxes and notifications from under the shell
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 outbefore 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 may slip a script that does something bad. And ok, if just the files in the system are deleted, you have fulfilled clause 1 of the Rules. (Really? Exactly sure? Okay, believe it.) Worse if the script sends something to a short number in Zimbabwe. Well, there is a credit card number, for example. What, no credit card? Nothing, SMS to a short number in Zimbabwe is not free, you know. And do not think that something will protect you, the script from the root will not be caught by either the antivirus or the various security managers. Of course, we will intervene quickly, and we will stop further spreading the malware. (But specifically your SMS will leave. 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 usenot a terminal emulator application, butadb (Android Debug Bridge) or ssh sessionFrom 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.


For questions of filling and updating the topic header, the Curator is always ready to help you.username11

Post has been editedusername11 - 10.11.18, 14:41
Reason for editing: added recipe about mtp
Grand1
Message#22
20.10.13, 21:20
Guru
*********
[offline]

Group: Developers
Messages 3569
Check in: 08.10.09
Samsung Galaxy Note 2 GT-N7100

Reputation:-  835  +

Guys, you need to give the user the choice of the file manager and the selected manager to open the folder / mnt / extSdCard / VideoReg, for example.
I do this:
am start -a android.intent.action.GET_CONTENT -c android.intent.category.DEFAULT -t folder / * -d '/ mnt / extSdCard / VideoReg ’

A selection window opens, for example, select Total Commander or EU Explorer, but the internal memory / storage / sdcard0 always opens
The parameter with the folder is not passed.
Why, who knows?

Post has been editedGrand1 - 20.10.13, 21:20


--------------------
username11
Message#23
21.10.13, 12:53
User
*********
[offline]

Topics Curator
Group: Curators
Messages 11374
Check in: 04.07.11
HTC Desire S

Reputation:-  2169  +

norbertano, date -s command. Any time synchronization (from the mobile network, via ntp, including indirect gps synchronization, must be disabled). I will repeat the warning here: if you constantly steal a time machine and ride a lot of it, Android will not like it very much. Not to mention the applications.
StimuliatorYou need to find the service / activity - the recipients of this intent and deny it (if nothing else in this service / activity is processed, of course). The list of objects you need is in the application manifest.
sv41, 1. You were half a step away from the decision! Instead of sending an application-specific intent, send your own, with the parameters you need. The application mentioned by you can take any intents.
2. "Keyboard driver" - never cool. All the dignity of the shell is that you write small scripts exclusively for your task. When scripts become rather big, find another tool. And to do something universal for a hundred or two lines on a shell does not make much sense. Although, yes, you can.
Nfc666 @ 10/19/2013, 18:37*
Try also options:
service call clipboard 1
service call clipboard 2
service call clipboard 3
...

So do not advise to indulge. You can drive Android into a very uncomfortable position. In extreme cases, do nandroid backup before such actions.
coolkaas, it is possible and in the main loop. Something like
[-z "$ timeout"] && read_opt = "" || read_opt = "- t $ timeout"; read $ read_opt. If the shell resists, then eval read $ read_opt.
Grand1, GET_CONTENT returns the data selected by the user, he needs to set the MIME data type. And if you just need to start the manager, then this is ACTION_VIEW, it requires uri. For example, file: // ..., but it can work without uri if the MIME type is specified. It strongly depends on the application.
Keyboard driver. I advise the one who will do it to pry into the source code of framework / base / core / java / android / view / KeyEvent.java, especially in the dispatch method. Not to wonder why Android doesn’t work as well as it did in the "driver".

Post has been editedusername11 - 05.11.18, 15:27
Grand1
Message#24
22.10.13, 07:51
Guru
*********
[offline]

Group: Developers
Messages 3569
Check in: 08.10.09
Samsung Galaxy Note 2 GT-N7100

Reputation:-  835  +

GET_CONTENT returns user-selected data, it needs to set the MIME data type.
Well, so you set:
GrAnd1 @ 10/20/2013, 10:20 PM*
I do this: am start -a android.intent.action.GET_CONTENT -c android.intent.category.DEFAULT-t folder / *-d '/ mnt / extSdCard / VideoReg'
I tried to transfer the path to the folder that I need to open in different ways and uri too, but the built-in memory / storage / sdcard0 or / mnt / sdcard always opens
GET_CONTENT does not pass the parameter with the path to the folder to the selected file manager, or I am doing something wrong.

For example, like this, Total opens the desired folder without problems:
am start -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -n com.ghisler.android.TotalCommander / .TotalCommander -d '/ mnt / extSdCard / VideoReg'

I apologize, I will finish this question and I will not offtopic anymore.
Although the am utility seems to relate to the shell ...


Post has been editedGrand1 - 22.10.13, 08:42


--------------------
Nfc666
Message#25
22.10.13, 10:19
Old resident
*******
[offline]

Group: Friendssavagemessiahzine.com
Messages 956
Check in: 01.04.12

Reputation:-  163  +

username11,In this case, nothing bad will happen, the clipboard is an innocuous service. ))) This is a remote communication interface between processes, the service command is just a console shell for working with this interface for debugging purposes. It was designed with the calculation of protection from a fool, which is why the transmitted data can be represented only by primitives and strings in it.
You can send anything to the process, if the request is correct, it will process it, if not, the corresponding message will be returned to you.
The danger here may be in another, in that if you poke buttons at random, then one day you can turn to some kind of securitypolicy (a fictitious name so that someone’s curiosity does not play a joke) service and call wipeall. : D

Post has been editedusername11 - 05.11.18, 15:14
Reason for editing: posts merged
username11
Message#26
22.10.13, 14:01
User
*********
[offline]

Topics Curator
Group: Curators
Messages 11374
Check in: 04.07.11
HTC Desire S

Reputation:-  2169  +

Grand1, folder / * does not look like the correct mime type for the directory. It seems that in Android it is vnd.android.cursor.item / directory, I just don’t know how many “conductors” know about it. Yes, ES knows about resource / folder, it seems.
mnt / extSdCard / VideoReg does not look like uri, there is no scheme. I, nevertheless, would add file: ///
It is necessary: ​​a) to look into the manifests of the conductors, what mime-types / uri they expect. b) look in packages.xml, there will be entries about default applications for mime types.
In general, with the "conductors" mess, there is someone who knows how and does. Most "know how" badly. Google aggravates the situation by the fact that there are no standard inode / directory, x-directory / normal mime types in Android.
You can still run just picker dialog, this is, exactly, action GET_CONTENT, category - android.intent.category.OPENABLE, mime type - * / *. Those. all that can be opened. I advise you to carefully read the description of the class Intent in Adnroid Reference Manual. There about GET_CONTENT is written.
Nfc666Even in this case there may be big problems. Most system services sit in the initial zygote process. Drop one of them, everyone will die. Further, it all depends on the specific manufacturer.
I now can not understand where such optimism? There are no fool defenses, the maximum for some services is the override of the onTransact method. And for the majority of service call it works, because for the base class an interlayer is created based on the table of public methods, and the transaction number will be an index in this table. And no protections, checks and other things. It is believed that the toad on the caller checked everything. And who managed to pull the method of service directly - SSZB. (Because it is not unmarked, it is impossible to call a method from the service. And for the majority of methods, even without a root.)
And with the clipboard service, it was simply that the method first checked the identity of the calling process and issued an echo. If he hadn’t done this, he would have taken the string and tried to work with it as with an object of the class ClipData, then the toad-runtime would have swatted it.
Here is the beginning of the source code path. Based on GB.
Interfaces are generated by aidl, a piece of code is frameworks / base / tools / aidl / generate_java.cpp, methods generate_interface_class, generate_method. You can see that this is a simple unpacking of a transaction and a call to a service method. The exception that arises goes on, i.e. in runtime. If you want to look at the code with your eyes, you can collect Android from the sources, look at the exhaust from under aidl. You can, however, on the Internet to find these ready-made files.
Yes, I recommend keeping Schreiber and other authors on hand. "Android Binder. Android Interprocess Communication".
Now if you want to drop something by yourself. Actually, you already know the method, service call with arbitrary arguments. If you want to fall hurt, take some PackageManager, brant it. If you want to get off with a slight fright, get the same Clipboard service. Does he check uid? Go to the uid of the application, which can change the contents of the clipboard. On the other hand, identity checking comes after clip.getItemCount (I’m already looking at source code 4.3), so you should get at least some exception just by passing garbage in the argument.
You have already been warned about possible troubles. I recommend to experiment all the same in the emulator, the standard Android simply scolds and restarts the service. Yes, and drop the emulator is not so scary.
And from where, in general, information about how "he" was designed? If you know for sure, piss where you know. We are just used to checking information. Do you know what fairy tales they sometimes write? Just amazing to fly fantasy. Hence the suspicion.

Post has been editedusername11 - 05.11.18, 15:30
madji
Message#27
24.10.13, 09:54
"... What will we have something? & We are
*******
[offline]

Group: Friendssavagemessiahzine.com
Messages 722
Check in: 10.12.10

Reputation:-  76  +

Guys help run this command (wrong commands on the android in tar), I can not understand myself.

find $ SITE_DIR-type f-mtime -1 -print | tar -zcvf $ DIR / daily / day_ $ TODAY.tar.gz -T - --exclude "cache">>/ dev / null 2>&1


--------------------
T-80
svs-57
Message#28
24.10.13, 10:42
Guru
*********
[offline]

Group: Friendssavagemessiahzine.com
Messages 7879
Check in: 18.05.08
Motorola Moto X Style XT1572

Reputation:-  727  +

madjiTry this:
tar -czvf $ DIR / daily / day_ $ TODAY.tar.gz `find $ SITE_DIR -type f -mtime -1` --exclude" cache ">> / dev / null 2> & 1

busybox should stand.


--------------------
Motolola X Style XT1572 32Gb stock, kernel frankenclark, TWRP;
SGS4 mini GT-I9195 4.2.2 ML1, kernel Vikinger;
ASUS Nexus N7 3G (2012) 4.4.4 ktu84p, the core of Carcosa a29, TWRP 2.8.5.1;
username11
Message#29
24.10.13, 17:03
User
*********
[offline]

Topics Curator
Group: Curators
Messages 11374
Check in: 04.07.11
HTC Desire S

Reputation:-  2169  +

madjiWhy do you need such tricks? If back up, back up everything, old, new. It is unlikely that you are able to score Gigabytes of memory with texts, why save on matches. (And if they are able, especially back up everything.) Ie simplify this to just tar with exclude cache. Yes, for some reason, the usual is -mtime 0, this is the full equivalent of -mtime -1. I don’t even know why, but -mtime -1 hurts the eyes. Still:>>in / dev / null - explicit brute force, -v simultaneously with>/ dev / null - also

Post has been editedusername11 - 05.11.18, 16:08
madji
Message#30
24.10.13, 17:58
"... What will we have something? & We are
*******
[offline]

Group: Friendssavagemessiahzine.com
Messages 722
Check in: 10.12.10

Reputation:-  76  +

username11,I understand what you mean.svs-57in the script there is a check for deleting old archives. I just started to study so there’s an obvious search somewhere, mainly in mana and examples, I think I will understand. I sometimes go far away from the original in php codes and often need a week option. I now looked at me, the 8.7 GB php code is clogged and often I lose a lot because of the fact that the code in the original correct.

Posted on 10/24/2013, 17:58:

Ask why? I’m in prison and there’s no computer and there’s no backup. I’ll be able to backup everything and so I sometimes get lost in files.


--------------------
T-80
svs-57
Message#31
24.10.13, 17:59
Guru
*********
[offline]

Group: Friendssavagemessiahzine.com
Messages 7879
Check in: 18.05.08
Motorola Moto X Style XT1572

Reputation:-  727  +

madjiIt depends on the $ TODAY format. I would replace this place with "date" in the right format. To be able to sort the archives and delete unnecessary. He did this more than once.


--------------------
Motolola X Style XT1572 32Gb stock, kernel frankenclark, TWRP;
SGS4 mini GT-I9195 4.2.2 ML1, kernel Vikinger;
ASUS Nexus N7 3G (2012) 4.4.4 ktu84p, the core of Carcosa a29, TWRP 2.8.5.1;
madji
Message#32
24.10.13, 18:05
"... What will we have something? & We are
*******
[offline]

Group: Friendssavagemessiahzine.com
Messages 722
Check in: 10.12.10

Reputation:-  76  +

svs-57like this
TODAY = `date +% F`
WEEKDAY = `date +% u`
MONTH = `date +% m.% Y`
Or no?

Post has been editedmadji - 24.10.13, 18:06


--------------------
T-80
username11
Message#33
24.10.13, 19:33
User
*********
[offline]

Topics Curator
Group: Curators
Messages 11374
Check in: 04.07.11
HTC Desire S

Reputation:-  2169  +

madji, DATE = $ (date + "% F:% m.% Y-% u")
date will display the formatted date as you wish. This is the shell interface to strftime.
svs-57
Message#34
24.10.13, 23:19
Guru
*********
[offline]

Group: Friendssavagemessiahzine.com
Messages 7879
Check in: 18.05.08
Motorola Moto X Style XT1572

Reputation:-  727  +

madjiI just meant thatusername11wrote. You must select a date format so that the files are sorted correctly.
True, it is not necessary. Could be so:
ls -lt / path-to-backup / | awk - '{print $ NF}' | wc -l total files
So if you need to leave 7, then it is easy to get the files you need to delete - instead of wc -l, put tail with the required number


--------------------
Motolola X Style XT1572 32Gb stock, kernel frankenclark, TWRP;
SGS4 mini GT-I9195 4.2.2 ML1, kernel Vikinger;
ASUS Nexus N7 3G (2012) 4.4.4 ktu84p, the core of Carcosa a29, TWRP 2.8.5.1;
madji
Message#35
25.10.13, 10:40
"... What will we have something? & We are
*******
[offline]

Group: Friendssavagemessiahzine.com
Messages 722
Check in: 10.12.10

Reputation:-  76  +

And so? find $ BACKUP / daily -type f -mtime +7 -exec rm -f '{}' \;


--------------------
T-80
username11
Message#36
25.10.13, 10:44
User
*********
[offline]

Topics Curator
Group: Curators
Messages 11374
Check in: 04.07.11
HTC Desire S

Reputation:-  2169  +

madji, how to make backups correctly (if you want not only to do it, but also recover successfully):
1. Create a list of files for backup. How exactly depends on the needs. In general, we form.
2. For each file, consider the checksum, for example, the command md5sum
3. Make a backup. Either using tar, or using bu (ics or higher).
4. Either directly to the backup, or next to we put counted checksums
5. After completing the archive operation, we check the integrity of the archive:
- we deploy the archive somewhere, but not to the place where we made the backup, of course.
- we consider checksums of files of the deployed archive, compare with previously calculated
If the archive is complete, rejoice. If not, we think a lot.

Post has been editedusername11 - 05.11.18, 16:12
coolkaas
Message#37
25.10.13, 17:32
viewer
*********
[offline]

Group: Friendssavagemessiahzine.com
Messages 5952
Check in: 09.11.10
Xiaomi Redmi 4X 3/32

Reputation:-  849  +

If the archive is complete

and in RAR there is an excess: rolleyes: is it possible in linux?

Post has been editedusername11 - 05.11.18, 16:12
Reason for editing: offtopic deleted
username11
Message#38
25.10.13, 19:49
User
*********
[offline]

Topics Curator
Group: Curators
Messages 11374
Check in: 04.07.11
HTC Desire S

Reputation:-  2169  +

coolkaas, it's not rar (which of course is for Linux, but nobody needs it). For example, you rolled up a rar beaten file (i.e., while rolling, it beat). And what to do when you had to restore? There is no file in the directory (otherwise, why restore), in the archive it is broken. It is better to check everything immediately.
It is clear that it is generally not necessary to disclose tar, but the script will become more complicated. It is possible to open for starters to check, and then optimize the script.
If the question is about the fundamental availability of redundancy, then bzip2, for example, has one. And if you want to manage it, then you can use the same parchive (it’s par, it’s par2) in Linux.
madji
Message#39
28.10.13, 09:48
"... What will we have something? & We are
*******
[offline]

Group: Friendssavagemessiahzine.com
Messages 722
Check in: 10.12.10

Reputation:-  76  +

It does not work, so in android.
in ubuntu it is so
find $ BACKUP / daily-type f - [b] atime [/ b] +7 -exec rm -f '{}' \; it seems to work.
still here with such syntax why works?
find $ BACKUP / daily -type f -mtime +7 -exec rm -f {} \;


Post has been editedmadji - 30.10.13, 17:54


--------------------
T-80
svs-57
Message#40
28.10.13, 12:20
Guru
*********
[offline]

Group: Friendssavagemessiahzine.com
Messages 7879
Check in: 18.05.08
Motorola Moto X Style XT1572

Reputation:-  727  +

madji
It is only necessary that the names of the backups when sorting old at the top - new at the bottom. So choose the date format in the name.
d = 7 # how many days to store
cd $ BACKUP / daily # go to backup
n = `ls -l | awk - '{if (NF> 5) print $ NF} | wc -l` # total files
n = $ (($ n - $ d)) # sk-ko need to be removed
if [$ n -gt 0]; then # if the number of removables> 0
rm -f `ls -l | awk - '{if (NF> 5) print $ NF}' | sort -r | tail - $ n` # sorted the list of files in reverse order, take the first n and delete
fi


--------------------
Motolola X Style XT1572 32Gb stock, kernel frankenclark, TWRP;
SGS4 mini GT-I9195 4.2.2 ML1, kernel Vikinger;
ASUS Nexus N7 3G (2012) 4.4.4 ktu84p, the core of Carcosa a29, TWRP 2.8.5.1;
username11
Message#41
29.10.13, 12:08
User
*********
[offline]

Topics Curator
Group: Curators
Messages 11374
Check in: 04.07.11
HTC Desire S

Reputation:-  2169  +

svs-57and why such delights?
svs-57 @ 10.28.2013, 13:20*
ls -l | awk - '{if (NF>5) print $ NF} '| wc -l

ls | wc -l

Although this is self-indulgence, find must be "repaired."

Post has been editedusername11 - 05.11.18, 16:15

369 pagesV  < 1 2 3 4 5 6 > » 


 mobile version    Now: 05/01/19 13:18