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)
sbit set, then changing the file will reset that bit. Ifselinuxenabled && echo Is enabledreturns 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 03 '15 at 08:41df -Th /etc– Huygens Jun 03 '15 at 11:00ext4. It says Filesystem/dev/rootis mounted on/– Steven Lu Jun 03 '15 at 16:00sudofor 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 03 '15 at 16:01sudo bash -c 'echo "startupcmd &" >> /etc/rc.local'orecho "startupcmd &" | sudo tee -a /etc/rc.localThose 2 commands will add the echoed data to the rc.local file, and it will be add by root. – Huygens Jun 04 '15 at 18:25sudo chmod +xline was being ineffectual in that I would need to runsudo bash -c 'chmod +x /etc/rc.local'– Steven Lu Jun 05 '15 at 02:58