启动脚本通过亚行根 [英] Launch a script as root through ADB

查看:125
本文介绍了启动脚本通过亚行根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个脚本来挂载分区,并做一些东西在我的Andr​​oid系统。我救了脚本install.sh Android中的/ bin文件夹。

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.

我想打电话给亚行的脚本,它本身就是从Windows上的批处理文件调用,但它需要以root身份执行。

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"

但它不工作,因为它给了我一个shell访问(使用root权限),但是在执行什么。 我也试着拨打

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"

对于所有需要我的脚本root权限,但我有同样的问题的命令。 当我运行该脚本一个root shell并没有执行我只得到。

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.

如果我用手工的第一个解决方案(例如:我叫亚行壳素,然后我的脚本),它的工作原理。然而,整点是自动的过程中,使亚行的shell可以从另一个脚本调用。

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 ?

谢谢!

推荐答案

这对我的作品:

创建myscript.bat投入它(请注意周围的命令,单引号以超级用户模式中执行):

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'"

然后myscript.bat在DOS shell中运行。

then run myscript.bat from a DOS shell.

请注意:它不会出现在DOS下续行符(^)的作品在这种情况下。换句话说,以下不为我工作:

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"

这篇关于启动脚本通过亚行根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆