LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Crontab for pkexec as root (https://www.linuxquestions.org/questions/linux-newbie-8/crontab-for-pkexec-as-root-893696/)

spyzer.abhishek0 07-25-2011 03:45 PM

Crontab for pkexec as root
 
Hello everyone,

I am trying to schedule a script through cron. This script utilizes pkexec for running a command. I as a user am able to run the command with pkexec for root. But when I schedule it through crontab then I keep getting the error Error executing command as another user: Not authorized. Please help.

MensaWater 07-25-2011 04:22 PM

Haven't used pkexec but after looking at it I'm not sure you need it.

We often run commands as other users from root's crontab by doing something like:

Code:

00 * * * * su - myuser -c "/path/to/myscript.pl" >> /var/log/myscript.prod 2>&1
This tells it to run the script called myscript.pl as the user, myuser, instead of as root.

spyzer.abhishek0 07-25-2011 04:57 PM

Thank you for the response.

The issue am facing is that when am trying to run my script without cron, in this manner
su - abhishek -c "/path/to/script" then its asking me password. Does that mean it shall keep
popping some GUI for the password every time it tries to run the script. That's not what I need.
I wanted it to run in background!!!

chrism01 07-25-2011 05:53 PM

As MensaWater pointed out, you use that technique from the root's(!) crontab; root doesn't require a passwd to login & run a cmd as another user.
You can try it by using 'su -' to get root and then run the cmd manually.
(If you're on ubuntu, I believe it's 'sudo su -')


All times are GMT -5. The time now is 04:24 PM.