2

I am wondering if this is behavior due to SELinux or something else.

I have a deploy script that I run and inside, I had sudo chmod +x /etc/rc.local, and some lines later I echo some startup commands, grep "startupcmd" /etc/rc.local || sudo echo "startupcmd &" >> /etc/rc.local

I found that this would always leave my /etc/rc.local non-executable.

I puzzled over it, then I thought Linux was somehow magically doing this to help me. So I move the chmod +x to the end of the file, and it works great now.

This was experienced on a Raspberry Pi 2 Debian (Raspbian), by the way. (which does not appear to have any SELinux set up)

closed as unclear what you're asking by Gilles, Stephen Kitt, G-Man, mdpc, Ramesh Jun 4 '15 at 0:10

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    I woudn't know about that but your sudo usage is strange (sudo echo...) I think that your script is running as root otherwise the redirection wouldn't work - so sudo seems useless. – cadrian Jun 3 '15 at 5:49
  • 3
    I can't reproduce. I know in some cases if you modify a file with the s bit set, then changing the file will reset that bit. If selinuxenabled && echo Is enabled returns nothing, SELinux is disabled. (However, being enabled, it might be set to permissive.) Also, I'm quite sure SELinux cannot be used to change the permissions of a file -- only deny the concatenate operation or future attempts to execute (regardless of bit). – Otheus Jun 3 '15 at 8:41
  • Could you let us know your filesystem? do df -Th /etc – Huygens Jun 3 '15 at 11:00
  • @Huygens it is ext4. It says Filesystem /dev/root is mounted on / – Steven Lu Jun 3 '15 at 16:00
  • @cadrian There does seem to be some non typical sudo behavior. If I do not write sudo for the echo that appends the line, it fails there. Indeed if i need to run the script sudo, then I would not need any sudo inside the script. Note also, at no time that sudo is used is the user's password ever requested. – Steven Lu Jun 3 '15 at 16:01

Browse other questions tagged or ask your own question.