0

I am trying to issue this command

adb shell "su -c echo 'boot-recovery' > /cache/recovery/command"
//OR//
adb shell "echo 'boot-recovery' > /cache/recovery/command"

outputs the same: /system/bin/sh: can't create /cache/recovery/command: Permission denied

I granted root permission for adb and i can run other commands with root normally like touch for example

I tried the command both ways when the file did and did not existed.

I tried checking for the existence of the file:

adb shell "if [ -f /cache/recovery/command ]; then echo "file found"; else echo "error"; fi"

it returned error even though the file does in fact exist

The Goal is to add a few lines to the recovery queue so the run the next time the device boots into recovery

Please correct me, I'm not so good at android command line, do I need to use a different command to achieve this goal?

More info: Android 8.1 (RR oreo) ... Magisk SU ... TWRP 3.2 (But need this to be compatible with as many android versions, recoveries, and su binaries as possbible .... I hope lol)

0
adb shell 'su -c "echo \"boot-recovery\" > /cache/recovery/command"'
adb shell 'su -c "'"echo "boot-recovery" > /cache/recovery/command"'"' #Alternative
adb shell "su -c \"echo 'boot-recovery' > /cache/recovery/command\"" #Another alternative
adb shell 'su -c "'"echo "'"boot-recovery"'" > /cache/recovery/command"'"' #yet another alternative

That should work. I'm not sure why. This answer from codeforester might help you out if you're looking for a reason.

My take is that, in:

adb shell "su -c echo 'boot-recovery' > /cache/recovery/command"

adb shell launches a non-interactive shell, the double quotes are expanded , leaving

su -c echo 'boot-recovery' > /cache/recovery/command

However, in this, only echo 'boot-recovery' gets to be run with root privilege and the resulting output falls back to shell user (id=2000) which doesn't have the privilege to write into cache directory, hence the error.

Quoting everything after -c passes whole echo 'boot-recovery' > /cache/recovery/command instruction to su executable, and so, that does work.

  • Thanks for the info .. how to avoid getting it in the hands of the user and keep it in root mode... are the 4 commands you wrote a solution? because they output the same Permission denied – NHKomaiha Sep 21 '18 at 20:15
  • I don't know why it outputs permission denied in your case. It works here. Does the shell/adb has permission to switch to root user in your superuser app? – Firelord Sep 22 '18 at 7:19
  • in magisk su it lets apps and adb have root access... I will try to play with another option related to owner/user/something root access – NHKomaiha Sep 22 '18 at 9:11
  • 1
    omg.. The 2nd one of your commands worked after i changed the Multi-user mode from Device Owner Only to User Independent... and now i opened the command file, it has "boot-recovery" in it (success) ..... It worked even tho powershell doesn't like it (it colors it wild) – NHKomaiha Sep 22 '18 at 9:18
  • Sorry for commenting a lot.. Now i tested it it does write to command but nothing happens when booting into recovery, so the main goal is not achieved – NHKomaiha Sep 22 '18 at 9:31
1

For me, this worked:

adb shell "su -c 'boot-recovery > /cache/recovery/command'"

You start with a double quote before su -c. Then single quote for the command, a single quote after the command and close with a double quote.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.