Ubuntu – bash profile works for user but not sudo

bash

I've modified my .profile to include a folder if a flash drive is plugged in. When running the command as the user it works fine but tells me the scrip must be run by sudo (this is what i want). However, when i try to run it with sudo i get "command not found"

I have a symlink (flash) in my /var/www folder pointing to my /media/flash drive. (nevermind this setup since is just for dev)

this is my user's .profile :

# set PATH so it includes flash scripts
if [ -d "/var/www/flash/scripts" ] ; then
    PATH="/var/www/flash/scripts:$PATH"
fi

when trying to run as sudo i get:

sudo: script: command not found    

any ideas?

Best Answer

When you run the script as sudo you are trying to access root. So your $HOME/.profile wont be accessed instead /root/.profile will be accessed.

So make the changes what ever you did in $HOME/.profile to /root/.profile. To create /root/.profile. Use the following commands.

sudo su
cd /root
touch .profile

after making the changes try running the script.

or edit $HOME/.bashrc and add the following line

alias sudo='sudo env PATH=$PATH $@'

Hope this helps.

Related Question