1

I have an alias in my .bashrc file that runs an executable python file like so:

alias my-command="sudo -u apache /path/to/file.py"

When I run my-command It prompts for my sudo password and then it runs the .py file.

However the python script writes to a Log file that only apache has permission to write to. When I run my-command it says Permission denied when it tries to write to that file.

When I run sudo -u apache /path/to/file.py directly the script runs fine.

What am I doing wrong here? Would it be better to change my alias to:

my-command="/path/to/file.py"

and then run:

sudo -u apache my-command
3
  • 2
    It shouldn't make any difference, which makes me think that you may not be doing what you think you're doing. Could you show us - cut-and-paste from terminal sessions into your question - rather than telling us?
    – MadHatter
    Mar 26, 2014 at 15:07
  • @MadHatter I took your advice and in the process of doing as you requested I found the issue... I will post it below. Thanks for the suggestion
    – ajon
    Mar 26, 2014 at 16:15
  • No worries - a surprising number of problems posted on SF boil down to "I wasn't doing exactly what I thought I was doing"! Thanks for bothering to come back and let us know what the issue was; don't forget to accept your own answer (when you can; it might take 48 hours or so), so this question doesn't float around forever.
    – MadHatter
    Mar 26, 2014 at 16:25

2 Answers 2

2

The issue had to do with relative paths. I was running the alias my-command from my home directory. My python script was writing to a file relative to the working directory. When I ran the command directly (without the alias) I was running it from the location of the python script, so that was the working directory, so the script had permission to write to the file.

So, when I run the alias command from the proper directory everything worked as expected.

0

If you would like that alias to work make sure that the user and group has the correct permissions to run that file - you also want to make sure that the same user is trying to run the alias for example you don't want to be foo user and your .bashrc is for bar user. I had that problem once I set the correct permissions it worked for me

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .