0

Considering there is hierarchy of directory in a mounted drive

|-ssd-drive
    |-main
        |-sub

Following are access of folder main, sub

 drwxrwxrwx. 12 poweruser devgroup 4096 Oct 26 18:45 main
 drwxrwxr-x. 8 poweruser poweruser 4096 Oct 26 19:01  sub

Now when I tried to run a shell script and on user poweruser behalf, and output the log under sub directory, it failed with permission issue

[myaccount@vm-002 log]$ sudo -u poweruser /script.sh  > /ssd-drive/main/sub/app.log 2>&1
-bash: /ssd-drive/main/sub/app.log: Permission denied

Why sudo -u poweruser doesn't work in this case? It's the owner of the owning directory 

Dreamer
  • 115

1 Answers1

1

As mentioned by steeldriver - the redirect is not part of the sudo.

a work around would be to run via bash:

sudo -u poweruser bash -c "/script.sh  > /ssd-drive/main/sub/app.log 2>&1"

This way the redirect is handled by a new instance of bash that is run as poweruser

Lutz
  • 126