Ask Your Question
1

sudo inside a script [closed]

asked 2014-10-22 14:38:27 -0600

bboran gravatar image

i have a myscript.sh file that is running at startup. there is a command inside that script file which needs to be run with sudo. how can i do this? command is;

/opt/flexnetserver/lmgrd -z -c lic.dat

what happens if i put sudo in front of this command? how its going to take admin rights without entering a password. i am a little bit confused. thanks.

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by randomuser
close date 2014-10-22 19:22:30.688343

Comments

This is the same problem you are trying to address in https://ask.fedoraproject.org/en/question/55746 . @bboran, if you ask a question and find an answer inadequate, please communicate the problem in that question rather than opening a new one.

randomuser gravatar imagerandomuser ( 2014-10-22 19:22:19 -0600 )edit

2 Answers

Sort by » oldest newest most voted
0

answered 2014-10-22 14:54:47 -0600

rsc gravatar image

This depends on your sudo configuration in "/etc/sudoers". Note that this file should be edited only using "visudo" (or a similar tool) but not directly using another editor (even that is technically possible). If you append something like

username ALL=(ALL) NOPASSWD: ALL

into that file, a user named "username" can run any command after sudo without being asked to type any password. For your specific case it could be:

Cmnd_Alias NETFLEX = /opt/flexnetserver/lmgrd
username ALL=(ALL) NOPASSWD: NETFLEX

Please keep in mind that above example is untested and might need some adjustions for your specific case.

edit flag offensive delete link more

Comments

tried it didnt work. also tried user ALL=(ALL) NOPASSWD: /opt/flexnetserver/lmgrd -z -c lic.dat it didnt work too. how can i check if my script.sh file starts at startup? also my script.sh file only contains the command inside it. is this the correct form of using a .sh file?

bboran gravatar imagebboran ( 2014-10-22 15:45:49 -0600 )edit

What did you try exactly? Actually something like

robert ALL=(ALL) NOPASSWD: ALL

has to work.

Regarding your second question: Please let us keep that question in https://ask.fedoraproject.org/en/question/55746/autorun-a-command-at-startup/ where it belongs to.

rsc gravatar imagersc ( 2014-10-23 01:19:38 -0600 )edit
-1

answered 2014-10-22 14:48:12 -0600

skytux gravatar image

It is possible to run a command with sudo without password. I think there is enough documentation on internet about this.

Please, Google it :-)

HTH,

Germán.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-10-22 14:38:27 -0600

Seen: 233 times

Last updated: Oct 22 '14