Root/non-root user permissions to edit file
Clash 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.
shell-script permissions root
 |Â
show 5 more comments
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.
shell-script permissions root
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
 |Â
show 5 more comments
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.
shell-script permissions root
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.
shell-script permissions root
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
 |Â
show 5 more comments
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
 |Â
show 5 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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