LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-25-2011, 04:45 PM   #1
spyzer.abhishek0
LQ Newbie
 
Registered: Jul 2008
Posts: 8

Rep: Reputation: 0
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.
 
Old 07-25-2011, 05:22 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,680
Blog Entries: 14

Rep: Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022
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.
 
Old 07-25-2011, 05:57 PM   #3
spyzer.abhishek0
LQ Newbie
 
Registered: Jul 2008
Posts: 8

Original Poster
Rep: Reputation: 0
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!!!
 
Old 07-25-2011, 06:53 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,258

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
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 -')
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
crontab : why root can't execute ?? bluenectar Linux - General 2 03-12-2007 04:21 AM
crontab as root nutthick Linux - Newbie 2 03-03-2005 03:13 AM
cannot use crontab as root???? rnj Linux - Software 2 10-24-2004 11:24 AM
root crontab plisken Slackware 8 05-02-2004 12:41 PM
problems with crontab for root reqvidd Linux - Newbie 2 11-10-2003 08:57 AM


All times are GMT -5. The time now is 11:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration