Solved Sudo command not working

I have a user test123 and added it to wheel group.
I have installed sudo program and uncommented the line

Code:
%wheel ALL = (ALL) NOPASSWD: ALL

When I get execute a python command
Code:
sudo cd /home/testapp && ./start.py
.I get error like
Code:
-bash: ./start.py: No such file or directory

For some reason the sudo command is not working.
 
Cd as a command is a little special, as it is built into the shell (it has to be, because one cannot change the directory of a running program from the outside; so to change the current directory, the shell has to run an internal command). So cd cannot be performed as a different user, I think. Instead you could probably do something like sudo python /home/testapp/start.py or perhaps sudo bash -c 'cd /home/testapp; ./start.py'.
 
You're telling it to do two separate commands, and only applying sudo to the first one. The second command is executed as the normal user. If the normal user doesn't have read/execute permission on /home/testapp directory, then the command will not be found.

As p3rj mentioned, you need to either give the full path to the program as the argument to sudo ( sudo /home/testapp/start.py) or you need to execute a sub-shell to chain the multiple separate commands together into one sudo command.

Alternatively, look at the first line in your start.py and make sure the #! (shebang) line points to an actual Python interpreter.
 
You're telling it to do two separate commands, and only applying sudo to the first one. The second command is executed as the normal user.
Yep, that's the issue.

Case in point:
Code:
dice@molly:~ % sudo id && id
Password:
uid=0(root) gid=0(wheel) groups=0(wheel),5(operator)
uid=1001(dice) gid=1001(dice) groups=1001(dice)
 
Cd as a command is a little special, as it is built into the shell (it has to be, because one cannot change the directory of a running program from the outside; so to change the current directory, the shell has to run an internal command). So cd cannot be performed as a different user, I think. Instead you could probably do something like sudo python /home/testapp/start.py or perhaps sudo bash -c 'cd /home/testapp; ./start.py'.

Your first solution
Code:
 sudo python /home/testapp/start.py
didn't work.
The 2nd one
Code:
 sudo bash -c 'cd /home/testapp; ./start.py'.
works perfectly.

I don't know why the first command didn't work
I even change python to python2.7 which I have installed on my server.

But no issues.Thank you for your solution
 
Back
Top