kypeli@ubuntu:~$ sudo ./myscript.sh [sudo] password for kypeli: sudo: ./myscript: command not foundObviously this was very strange to me because the script was in the current working directory, all permissions looked fine and I could run the script just fine without sudo, which indicated that the shebang was ok.
kypeli@ubuntu:~$ls -la ./script.sh -rwxr-xr-x 1 root root 568 2012-02-13 05:49 ./script.sh
kypeli@ubuntu:~$So what has happened? Apparently Ubuntu changed something in some update (I am still to verify this) which prevents me from running scripts as sudoer from other than sudo compile time predefined paths. You can verify this by looking at the flags that were used to compile sudo and look for the --with-secure-path option. sudo will not run any script (or command for that matter) outside of these paths. Including .
./script.shUsage: ./script.sh [foobar] Give 'foobar' to do Baz
kypeli@ubuntu:~$ cat /usr/share/doc/sudo/OPTIONS ... --with-secure-path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin"
Give a reasonable default path for commands run as root via sudo.Well - this was a bit annoying to me for two reasons. I am pretty sure this worked for me last week on my Ubuntu, but suddenly it doesn't work anymore. And secondly, I am not running any public server and I want to run my own scripts with root privileges (why I want to do that is a different topic :)) if I so choose. I must stress that I can see the reasons for doing this and security is always a trade off between security and usability. I would not do this on any public server, but for Ubuntu to not allow me to run my own commands as root is a bit annoying.
And the run source $HOME/.bashrc (this will not be necessary on subsequent boots or starts of the terminal). You should again be bale to run your scripts with sudo. This will enable the fix only for me, as I put the alias in my .bashrc file, so it's not even a terrible security risk. And that's fine. I would also like to thank @anidel for pointing out initially this possibility.alias sudo='sudo env PATH=$PATH $@'