Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a command without sudo?

Tags:

linux

shell

I want to add a line in the crontab (on my local machine) which will run every five minutes. My problem is the command I am going to use requires sudo :

sudo indexer --config /usr/local/etc/sphinx.conf --all --rotate

Is there a way I can run the command without using sudo and without prompting for password ?

Thanks!

like image 918
r2b2 Avatar asked Aug 06 '10 07:08

r2b2


2 Answers

Put it in the crontab of root

sudo crontab -e

There you can put

indexer --config /usr/local/etc/sphinx.conf --all --rotate

All commands in this crontab will be executed as root. If you just du crontab -e as your current user, they will be executed under your users permissions.

like image 167
JochenJung Avatar answered Sep 28 '22 09:09

JochenJung


Just append your command to the sudoer file list by using cmd visudo(this cmd requires root priviledge) as below:

<YOUR_USER_NAME> ALL = NOPASSWD:<ABSOLUTE-PATH-TO-CMD>

Take care of the ABSOLUTE-PATH-TO-CMD,It may become a security hole.

like image 39
schemacs Avatar answered Sep 28 '22 07:09

schemacs