LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 03: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, 04:22 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
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, 04: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, 05:53 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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



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 03:21 AM
crontab as root nutthick Linux - Newbie 2 03-03-2005 02:13 AM
cannot use crontab as root???? rnj Linux - Software 2 10-24-2004 10:24 AM
root crontab plisken Slackware 8 05-02-2004 11:41 AM
problems with crontab for root reqvidd Linux - Newbie 2 11-10-2003 07:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:08 PM.

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
Open Source Consulting | Domain Registration