Run a Script as Non-Root User – Command-Line Guide

bashcommand linepermissionsscripts

I want to run a script say requires root permissions, contains some sudo do something in a for loop) as non-root user. I have a script as shown below. I want to run this script as root and using this I want to run the other one

while true
    if [ some conditioon ] 
        sudo &
        sleep 30
        exit 0


  • is in PATH and I want that to go on checking at each 30 sec
  • It is executing smoothly if I run from terminal as sudo, when I am going to run it using above script it is doing its job partially.

Is it possible to do like this? if yes then what are the problems above, show me any better way.


please take a look at this. Please read as of that answer.

Best Answer

If you just want the script to run as root every 30 minutes, use cron.

Edit the file /etc/crontab to contain the following:

#minute hour    mday    month   wday    user    command
*/30    *       *       *       *       root