Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 07-25-2011, 04:45 PM   #1
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
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,075
Blog Entries: 14

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

00 * * * * su - myuser -c "/path/to/" >> /var/log/ 2>&1
This tells it to run the script called as the user, myuser, instead of as root.
Old 07-25-2011, 05:57 PM   #3
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
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

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


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 > Forums > Linux Forums > Linux - Newbie

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

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