1

Linux Mint.

Ok, this is going to be seriously basic but for some reason, I am mis-understanding how this works.

If I type the following commands, everything works fine:

cd home/user/folder1/folder1/

sudo openvpn --auth-nocache --config /home/user/folder2/folder2/config-file.ovpn 

I input the sudo password and all is good.

If I put these commands into a script file, I get nothing but 'command not found'.

I have placed the script file in a folder, added both the script AND the opvn folders to the path.

I created a new script (without the paths) in the same folder as the opvn files, ran it from there and fail.

sudo opvn-script.sh 
[sudo] password for <user>: 
sudo: opvn-script.sh: command not found

What I don't understand is the script file itself can't be the thing 'not found' because it auto-completes after I type a the first few characters and hit tab. openvpn can't be the 'not found' because I can run the commands straight up.

The script file IS marked as executable.

echo $PATH shows both folders in the path.

What the heck is left??

4
  • 2
    Different users have different PATHs. It would seem that opvn-script.sh is in the PATH for the current user but not for root. Try: sudo /path/to/opvn-script.sh
    – John1024
    Feb 24, 2015 at 6:26
  • Yup, that did it! So, what is best then? Add the path to su by switching to su, export path?
    – DragonDon
    Feb 24, 2015 at 6:33
  • There are many solutions. One might be to create a shell alias that types out sudo /path/to/opvn-script.sh for you. Another might be just to move opvn-script.sh to some convenient place on root's current PATH.
    – John1024
    Feb 24, 2015 at 6:37
  • Thanks again. The alias seems less secure than simply moving the script somewhere.
    – DragonDon
    Feb 24, 2015 at 6:39

3 Answers 3

1

Consider this error message:

sudo: opvn-script.sh: command not found

This occurred after you entered the password and indicates that, under the PATH of the new user (root), the script could not be found.

One solution is:

sudo /path/to/opvn-script.sh 

If that works, then move opvn-script.sh to a convenient location somewhere on root's PATH.

For security, make sure that permissions are set so that only root can modify (write) opvn-script.sh.

1

Ah, I think I see it. (Hard to tell remotely of course, and I don't have a linux box at hand.)

When you run a command via sudo, ie

$ sudo blah

there's a potential security hole -- consider, eg, if someone edited your script and added vi /etc/passwd to it. I beleive Linux changes the path to prevent this.

To check, write a script that just echoes $PATH and run it from sudo. If the path is not what you expect, you've found your problem.

1
  • 1
    Thanks Charlie! Seems you and @John1024 came to the same conclusion because I got the same "not found" when I tried another script. Albeit yours mostly confirmed his in a different way :)
    – DragonDon
    Feb 24, 2015 at 6:35
1

Path to script was not in SUDO user profile, moved script to a SUDO path

3
  • Please mark this as accepted so that this question no longer comes up as unresolved. Thanks.
    – tripleee
    Feb 24, 2015 at 7:57
  • Err, how does one do that in the Android app? Nothing is obvious.....
    – DragonDon
    Feb 24, 2015 at 8:06
  • Ah, just figured out out but I can accept my own answer till two days have passed.
    – DragonDon
    Feb 24, 2015 at 8:08

You must log in to answer this question.

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