简体   繁体   中英

Automating adb shell commands using batch(.bat) files

I regularly grant read/write/execute (chmod 777) permissions to different system files in Android phones(rooted phones). Sometimes I add the chmod 777 command to the startup script, Just to save time. On Samsung Galaxy S6 phone I am updating the file(script): '/etc/init.sec.boot.sh', adding following command at the end of the file.

chmod 777 <filename>

This works fine from inside the adb shell using the following command

su
echo 'chmod 777 <filename>' >> /etc/init.sec.boot.sh

Now if I try to the same using a .bat file it gives me permission error. I am using the following command

adb shell su -c "echo \"chmod 777 <filename>\" >> /etc/init.sec.boot.sh"

Since this command was not working I copied the file to sdcard, modified it and then replaced the original file with the modified version. If I now read the contents of the file it reads exactly what I wanted, but the chmod command is never executed. I restarted the phone several times but the file permission were not effected at all. At this point if I run same command from inside the shell if works.

su
echo 'chmod 777 <filename>' >> /etc/init.sec.boot.sh

At this point the last two lines in the init.sec.boot.sh files read like this.

chmod 777 <filename>
chmod 777 <filename>

The last two lines seems exactly the same. The chmod command only works when it is written from inside the shell. The only reasonable explanation I could think of is that there may be a different text encoding used by the windows command prompt and Android linux shell. How to successfully execute the chmod command from .bat files (or even directly from command prompt).

PS: I did remounted /system to read/write.

I guess the problem was the difference between the Windows EOL and Unix EOL.

So I created a script inside the Linux System (Androids Linux System), to do the chmod stuff. Used adb pull command to copy the .sh file to my Windows machine.

Now my original batch file copies this script back to the phone and executes it. (I had to copy the script to /data/local inside the phone). This is working perfectly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM