First of all, I'm experimenting a DVFS with my rooted phone, Galaxy A12. Nevertheless, if I use a command inside of adb shell then it does not throw a Permission Denied.
~$ adb shell
a12:/ $ su
a12:/ # echo 500000 > sys/kernel/gpu/gpu_max_clock
a12:/ #
However, when I use this command outside of android kernel with adb shell su -c, it throws a Permission denied
~$ adb shell su -c "echo 680000 > sys/kernel/gpu/gpu_max_clock"
/system/bin/sh: can't create sys/kernel/gpu/gpu_max_clock: Permission denied
I've tried some commands like the below, however the commands threw the same thing.
adb shell su -c "chmod 755 sys/kernel/gpu/gpu_max_clock && echo 680000 > sys/kernel/gpu/gpu_max_clock"
adb shell su -c "chmod 777 sys/kernel/gpu/gpu_max_clock && echo 680000 > sys/kernel/gpu/gpu_max_clock"
How can I handle this situation?
A shell terminal does not throw any exceptions and your command line is wrong - the path, too:
adb shell "su -c 'echo 680000 > /sys/kernel/gpu/gpu_max_clock'"
You might end up with a defect GPU, when not having the slightest clue of what you're doing.
Better research the max values first - when it goes up in smoke, this is your own fault, not mine.
Any sane person would probably read the original clock speed first:
cat /sys/kernel/gpu/gpu_max_clock
Only then one can see, how many percent of the original clock speed 680000 would even be.
When giving to much, this will lead to overheating and random crashes... unless also reducing the voltage. This is by far not as easy as you may think it is ...and there is no active cooling available, either.
Your command line is wrong. Try this.
adb shell "su -c 'echo 680000 > /sys/kernel/gpu/gpu_max_clock'"
or
adb shell "su -c 'chmod 777 /sys/kernel/gpu/gpu_max_clock && echo 680000 > /sys/kernel/gpu/gpu_max_clock'"
Related
I need to make a script that executes a lots of thing on Android device, my device is rooted, when I enter on the shell, I can give the command su, and it works but I need pass this command like:
adb shell "
su;
mv /sdcard/Download/app_test /data/local;
cd /data/local;
./app_test;
exit;
exit;
"
when I put some commands before the su it works, according what I read su creates a new shell that return immediately, but I need give commands on the su shell, how can I do that?
Well, if your phone is rooted you can run commands with the su -c command.
Here is an example of a cat command on the build.prop file to get a phone's product information.
adb shell "su -c 'cat /system/build.prop |grep "product"'"
This invokes root permission and runs the command inside the ' '.
Notice the 5 end quotes, that is required that you close ALL your end quotes or you will get an error.
For clarification the format is like this.
adb shell "su -c '[your command goes here]'"
Make sure you enter the command EXACTLY the way that you normally would when running it in shell.
On my Linux, I see an error with
adb shell "su -c '[your command goes here]'"
su: invalid uid/gid '-c'
The solution is on Linux
adb shell su 0 '[your command goes here]'
The su command does not execute anything, it just raise your privileges.
Try adb shell su -c YOUR_COMMAND.
By default CM10 only allows root access from Apps not ADB. Go to Settings -> Developer options -> Root access, and change option to "Apps and ADB".
1. adb shell su
win cmd
C:\>adb shell id
uid=2000(shell) gid=2000(shell)
C:\>adb shell 'su -c id'
/system/bin/sh: su -c id: inaccessible or not found
C:\>adb shell "su -c id"
uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0
C:\>adb shell su -c id
uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0
win msys bash
msys2#bash:~$ adb shell 'su -c id'
uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0
msys2#bash:~$ adb shell "su -c id"
uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0
msys2#bash:~$ adb shell su -c id
uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0
2. adb shell -t
if want run am cmd, -t option maybe required:
C:\>adb shell su -c am stack list
cmd: Failure calling service activity: Failed transaction (2147483646)
C:\>adb shell -t su -c am stack list
Stack id=0 bounds=[0,0][1200,1920] displayId=0 userId=0
...
shell options:
shell [-e ESCAPE] [-n] [-Tt] [-x] [COMMAND...]
run remote shell command (interactive shell if no command given)
-e: choose escape character, or "none"; default '~'
-n: don't read from stdin
-T: disable pty allocation
-t: allocate a pty if on a tty (-tt: force pty allocation)
-x: disable remote exit codes and stdout/stderr separation
Android Debug Bridge version 1.0.41
Version 30.0.5-6877874
for my use case, i wanted to grab the SHA1 hash from the magisk config file. the below worked for me.
adb shell "su -c "cat /sbin/.magisk/config | grep SHA | awk -F= '{ print $2 }'""
I opt for the following:
adb shell su root <your command>
e.g., to access the external storage (sd card):
adb shell su root ls storage/0/emulated
I want to type multiple adb shell commands in one line, for example, i want to type adb shell and su and cd sys together. i tried to connect them with && and & bzw.adb shell && su && cd sys, but it seems like not work with adb commands, but works with windows commands. does anybody knows what is the problem?
Sovled by myself adb shell "su -c 'cd sys'"
I'm using an Android-x86 vm running in vmware fusion for some testing purposes. I am pushing files to it via adb push, however, every time I uninstall and reinstall the app, I have to execute the following:
adb shell
su
chmod 777 /my/path
exit
exit
I need to be able to script out this entire process but I'm not sure how I can manage the chmod process via some sort of script. I tried doing something like
adb shell am chmod 777 /my/path
But that doesn't work. I thought it would because I can do
adb shell am start ...
I also tried:
adb shell "su && chmod 777 /my/path && exit && exit"
which actually works, but doesn't exit the shell process. So any advice is much appreciated.
You can pass commands to adb shell, as you mentioned, though it works better if you surround the command in quotes.
Likewise, you can pass commands to the 'su' command using the -c argument. Add all of this together and it should do what you want in a nice one-liner!
adb shell "su -c 'chmod 777 /my/path'"
One problem with ADB is that you need multiple commands to get things done.
For example:
adb shell
su
cp /data/local/x /data/local/y
exit
adb pull /data/local/y
Can this be done using python popen and os-system? Tried the example below without success..
print 'Starting emulator...'
subprocess.Popen(['emulator', '-avd', 'testavd'])
os.system('adb wait-for-device')
os.system('Perform whatever adb commands you need')
Any pointers?
You can simply do:
adb shell su -c cp /data/local/x /data/local/y
adb pull /data/local/y
or, if you want to run more than one command (only Linux & OSX):
adb shell <<EOF
ls
date
cat /proc/version
exit
EOF
I have created a script to mount partitions and do some stuff in my Android system. I saved the script as install.sh in the /bin folder of Android.
I want to call the script from ADB, which is itself called from a batch file on Windows, but it needs to be executed as root.
The first solution I tried was to call the script using
adb shell "su -c sh /bin/script.sh"
but it does not work as it gives me a shell access (with root permissions), but nothing is executed.
I also tried to call
adb root "sh /bin/script.sh"
but I got the following error
adbd cannot run as root in production builds
I then tried to write
su -c "command"
for all the commands which need a root access in my script, but I have the same problem.
When I run the script I only obtain a root shell and nothing is executed.
If I use the first solution by hand (e.g. I call adb shell su, then my script), it works. However the whole point is to automate the process, so that adb shell can be called from another script.
Do you have any idea of how I could achieve this ?
Thanks !
This works for me:
Create myscript.bat and put into it (note the single quotes around the commands to be executed in superuser mode):
adb shell "su -c 'command1; command2; command3'"
then run myscript.bat from a DOS shell.
Note: it doesn't appear that the the DOS line continuation character (^) works in this situation. In other words, the following doesn't work for me:
adb shell "su -c '^
command1; ^
command2; ^
command3'"
This results in "Syntax error: Unterminated quoted string"
This works :
adb shell echo command which needs root privileges \| su
If you need redirection:
adb shell echo 'echo anytext > /data/data/aforbiddenfolder/file' \| su
For "copying" a local file to an android path needing root privileges (but alocalfile must not contain '):
cat alocalfile | adb shell echo "echo '`cat`' > /data/data/aforbiddenfolder/file" \| su
If you have a better way (even for su versions which don't have -c), I am interested.
This works for me:
adb shell "su -c ./data/local/tcpdump-arm -s 0 -v -w /data/local/appxpress_dump.pcap"
I am not sure if I provided a solution or asked for a better one.
I wanted to run some 200 command in batch mode to be sent to adb
I followed this approach
adb shell "su -c command ; "
adb shell "su -c command ; "
adb shell "su -c command ; "
adb shell "su -c command ; "
and I saved them in a batch file
This command
adb shell "su -c 'command1; command2; command3'"
will not work beyond a certain max size . It did not work
error: service name too long
but it does not work as it gives me a shell access (with root permissions), but nothing is executed.
How do you know that you are given root permissions? I assume you are attempting to execute the script on a device? Has your device been rooted?
You may need to give execute permissions via chmod to the file.
chmod ugo=rwx /bin/script.sh
It appears that I was using a very simple version of su which did not accept the -c argument.
I copied another su which did work. AndyD is totally right though, so I am accepting his answer instead of mine :)