Root/non-root user permissions to edit file

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I am running scriptA.sh as root. Inside the script I need to echo data into FileA. FileA is owned by user1. FileA is located under /usr/local and has the following permissions:



-rw-r----- 1 user1 group 


FileA permissions cannot be modified. Right now, when I run scriptA I get permission denied on FileA. Is there anyway to get around this inside the script?



Psuedo code from scriptA that writes to FileA:



function update_FileA()

if [ condition ] then
echo "XYZ data" >> FileA
else
echo "ABC data" >> FileA
fi



Update: Tried a few things. I tried to vi FileA as user1 and as root and I was able to successfully edit. Its only when trying to edit the file through the script write access is denied.







share|improve this question





















  • echo foo | sudo -u user1 tee FileA, perhaps. How exactly are you executing the script and how exactly are you echoing data to the file?
    – muru
    Jun 21 at 5:18










  • Root has permission to read all files, can you show the contents of scriptA.sh
    – Arushix
    Jun 21 at 5:22










  • @muru, tried ur suggestion, still seeing permission denied. I am logged in as root and then script is executed from the terminal-> ./scriptA.sh
    – sotn
    Jun 21 at 5:35






  • 2




    Then it's an selinux issue.
    – roaima
    Jun 21 at 8:10






  • 2




    Or perhaps the file has the "immutable" attribute set? (check with the lsattr command) Or maybe the system has detected some filesystem corruption and switched to read-only mode?
    – telcoM
    Jun 21 at 14:47














up vote
0
down vote

favorite












I am running scriptA.sh as root. Inside the script I need to echo data into FileA. FileA is owned by user1. FileA is located under /usr/local and has the following permissions:



-rw-r----- 1 user1 group 


FileA permissions cannot be modified. Right now, when I run scriptA I get permission denied on FileA. Is there anyway to get around this inside the script?



Psuedo code from scriptA that writes to FileA:



function update_FileA()

if [ condition ] then
echo "XYZ data" >> FileA
else
echo "ABC data" >> FileA
fi



Update: Tried a few things. I tried to vi FileA as user1 and as root and I was able to successfully edit. Its only when trying to edit the file through the script write access is denied.







share|improve this question





















  • echo foo | sudo -u user1 tee FileA, perhaps. How exactly are you executing the script and how exactly are you echoing data to the file?
    – muru
    Jun 21 at 5:18










  • Root has permission to read all files, can you show the contents of scriptA.sh
    – Arushix
    Jun 21 at 5:22










  • @muru, tried ur suggestion, still seeing permission denied. I am logged in as root and then script is executed from the terminal-> ./scriptA.sh
    – sotn
    Jun 21 at 5:35






  • 2




    Then it's an selinux issue.
    – roaima
    Jun 21 at 8:10






  • 2




    Or perhaps the file has the "immutable" attribute set? (check with the lsattr command) Or maybe the system has detected some filesystem corruption and switched to read-only mode?
    – telcoM
    Jun 21 at 14:47












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am running scriptA.sh as root. Inside the script I need to echo data into FileA. FileA is owned by user1. FileA is located under /usr/local and has the following permissions:



-rw-r----- 1 user1 group 


FileA permissions cannot be modified. Right now, when I run scriptA I get permission denied on FileA. Is there anyway to get around this inside the script?



Psuedo code from scriptA that writes to FileA:



function update_FileA()

if [ condition ] then
echo "XYZ data" >> FileA
else
echo "ABC data" >> FileA
fi



Update: Tried a few things. I tried to vi FileA as user1 and as root and I was able to successfully edit. Its only when trying to edit the file through the script write access is denied.







share|improve this question













I am running scriptA.sh as root. Inside the script I need to echo data into FileA. FileA is owned by user1. FileA is located under /usr/local and has the following permissions:



-rw-r----- 1 user1 group 


FileA permissions cannot be modified. Right now, when I run scriptA I get permission denied on FileA. Is there anyway to get around this inside the script?



Psuedo code from scriptA that writes to FileA:



function update_FileA()

if [ condition ] then
echo "XYZ data" >> FileA
else
echo "ABC data" >> FileA
fi



Update: Tried a few things. I tried to vi FileA as user1 and as root and I was able to successfully edit. Its only when trying to edit the file through the script write access is denied.









share|improve this question












share|improve this question




share|improve this question








edited Jun 21 at 15:40
























asked Jun 21 at 5:16









sotn

1011




1011











  • echo foo | sudo -u user1 tee FileA, perhaps. How exactly are you executing the script and how exactly are you echoing data to the file?
    – muru
    Jun 21 at 5:18










  • Root has permission to read all files, can you show the contents of scriptA.sh
    – Arushix
    Jun 21 at 5:22










  • @muru, tried ur suggestion, still seeing permission denied. I am logged in as root and then script is executed from the terminal-> ./scriptA.sh
    – sotn
    Jun 21 at 5:35






  • 2




    Then it's an selinux issue.
    – roaima
    Jun 21 at 8:10






  • 2




    Or perhaps the file has the "immutable" attribute set? (check with the lsattr command) Or maybe the system has detected some filesystem corruption and switched to read-only mode?
    – telcoM
    Jun 21 at 14:47
















  • echo foo | sudo -u user1 tee FileA, perhaps. How exactly are you executing the script and how exactly are you echoing data to the file?
    – muru
    Jun 21 at 5:18










  • Root has permission to read all files, can you show the contents of scriptA.sh
    – Arushix
    Jun 21 at 5:22










  • @muru, tried ur suggestion, still seeing permission denied. I am logged in as root and then script is executed from the terminal-> ./scriptA.sh
    – sotn
    Jun 21 at 5:35






  • 2




    Then it's an selinux issue.
    – roaima
    Jun 21 at 8:10






  • 2




    Or perhaps the file has the "immutable" attribute set? (check with the lsattr command) Or maybe the system has detected some filesystem corruption and switched to read-only mode?
    – telcoM
    Jun 21 at 14:47















echo foo | sudo -u user1 tee FileA, perhaps. How exactly are you executing the script and how exactly are you echoing data to the file?
– muru
Jun 21 at 5:18




echo foo | sudo -u user1 tee FileA, perhaps. How exactly are you executing the script and how exactly are you echoing data to the file?
– muru
Jun 21 at 5:18












Root has permission to read all files, can you show the contents of scriptA.sh
– Arushix
Jun 21 at 5:22




Root has permission to read all files, can you show the contents of scriptA.sh
– Arushix
Jun 21 at 5:22












@muru, tried ur suggestion, still seeing permission denied. I am logged in as root and then script is executed from the terminal-> ./scriptA.sh
– sotn
Jun 21 at 5:35




@muru, tried ur suggestion, still seeing permission denied. I am logged in as root and then script is executed from the terminal-> ./scriptA.sh
– sotn
Jun 21 at 5:35




2




2




Then it's an selinux issue.
– roaima
Jun 21 at 8:10




Then it's an selinux issue.
– roaima
Jun 21 at 8:10




2




2




Or perhaps the file has the "immutable" attribute set? (check with the lsattr command) Or maybe the system has detected some filesystem corruption and switched to read-only mode?
– telcoM
Jun 21 at 14:47




Or perhaps the file has the "immutable" attribute set? (check with the lsattr command) Or maybe the system has detected some filesystem corruption and switched to read-only mode?
– telcoM
Jun 21 at 14:47















active

oldest

votes











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f451019%2froot-non-root-user-permissions-to-edit-file%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes










 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f451019%2froot-non-root-user-permissions-to-edit-file%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?