0

I want to run a script say some_script.sh(that 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 some_script.sh.

#!/bin/bash
while true
do
    if [ some conditioon ] 
    then
        sudo some_script.sh &
        sleep 30
    else
        exit 0
    fi
done

Note

  • some_script.sh is in PATH and I want that to go on checking at each 30 sec
  • It is executing smoothly if I run some_script.sh from terminal as sudo some_script.sh, 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.

Edit

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

  • What are you trying to do in the big picture? What is some_script.sh ? – kiri Nov 21 '13 at 2:40
0

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    some_script.sh

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.