LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 02-03-2017, 08:24 AM   #1
avalenti3
LQ Newbie
 
Registered: Feb 2017
Posts: 4

Rep: Reputation: Disabled
Cron Job Set to Run as User, Running with User as Part of the Command


I have a crontab file setup like this to run as the root user:

*/10 * * * * root /opt/inmar/dmt/proxyCheck.py

But every time that it runs, it runs once correctly with 'root' as the user and '/opt/inmar/dmt/proxyCheck.py' as the command and it also runs with 'root /opt/inmar/dmt/proxyCheck.py' as the command. This is evidenced in the syslog:

Feb 1 10:30:01 CORP-MSQLPRX1 CRON[16152]: (root) CMD ( /opt/inmar/dmt/proxyCheck.py)
Feb 1 10:30:02 CORP-MSQLPRX1 CRON[16153]: (root) CMD (root /opt/inmar/dmt/proxyCheck.py)

This is not the only cron job that runs like this. There are others where it is mistaking the user as part of the command line. How can I set it up properly and how do I get rid of the bad cron task that keeps running?

Thanks,
Anthony
 
Old 02-03-2017, 09:05 AM   #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
You don't need "root" in the crontab entry if the crontab is root's crontab. The crontabs run as the user that owns the crontab. So your entry in root's crontab should just be:
Code:
*/10 * * * * /opt/inmar/dmt/proxyCheck.py
 
Old 02-03-2017, 09:12 AM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
In addition what linux distribution/version are you running? Are you using a system cron job i.e you added it to /etc/crontab?
 
Old 02-03-2017, 10:02 AM   #4
avalenti3
LQ Newbie
 
Registered: Feb 2017
Posts: 4

Original Poster
Rep: Reputation: Disabled
We are running CentOS 6 and 7. We also se this on Some Ubuntu 12 and 14 servers.
The /etc/crontab has an example that looks like this:
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed

We have multiple crontab files in /etc/cron.d that are supposed to run as different users, with the crontab files being owned by root.
The really weird thing is that it simultaneously works correctly and doesn't. I would think that it would be one or the other.
Here is another example in the cron log were it ran both ways for a user other than root:
Feb 2 00:00:01 pwslhdpedgecp001 CROND[25828]: (kodoop) CMD (/opt/inmar/kognitio/kognitio_stop.sh) <--- Correct
Feb 2 00:00:01 pwslhdpedgecp001 CROND[25829]: (root) CMD (kodoop /opt/inmar/kognitio/kognitio_stop.sh) <--- Not Correct
 
Old 02-03-2017, 10:52 AM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
At the moment I do not understand why the job is running twice? Do you have multiple cron jobs for the same task?
 
Old 02-03-2017, 11:21 AM   #6
avalenti3
LQ Newbie
 
Registered: Feb 2017
Posts: 4

Original Poster
Rep: Reputation: Disabled
No, that is what I don't understand either and why I am asking the question, hoping that someone else has seen this before or can point me in the right direction. There is only one crontab file with this job. I created the crontab file in /etc/cron.d and sudoed as root, I run:
crontab <filename>
crontab -e
(save the crontab with :wq)
it says 'crontab: installing new crontab'
That's it. Pretty simple.

Last edited by avalenti3; 02-03-2017 at 11:34 AM. Reason: added the location of file created
 
Old 02-03-2017, 11:34 AM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
You posted that you created cron jobs in /etc/cron.d which are system jobs and not the same thing as root's cron jobs which are saved in /var/spool/cron when you use crontab -e. The jobs create using crontab -e do not need a user-name.

If you added the same command when you run crontab -e then you are running it twice.

Last edited by michaelk; 02-03-2017 at 11:47 AM. Reason: responded to additional information.
 
Old 02-03-2017, 11:57 AM   #8
avalenti3
LQ Newbie
 
Registered: Feb 2017
Posts: 4

Original Poster
Rep: Reputation: Disabled
So if I put the file in /etc/cron.d, don't use crontab -e. How do I remove the crontab -e version?
 
Old 02-03-2017, 12:36 PM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
Ok, here is a better explanation after a bit of thinking I think. By running crontab <filename> as root you switched its default cron file from /var/spool/cron/root to /etc/cron.d/<filename> so it is running it twice i.e. as a system job and as root.

If you switch root's cron back i.e run crontab /var/spool/cron (as root) that should work although you could run crontab -e and then save a blank file via :wq just to "refresh" crond.
 
  


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
Run cron job with different User kunalks Linux - Server 7 06-19-2014 11:18 PM
[SOLVED] Running a cron job as a user laredotornado Linux - Newbie 7 05-05-2011 11:43 AM
[SOLVED] Not able to run cron job for non-privileged user in RHEL 5.3 mail4vijay Linux - General 3 11-24-2009 10:18 AM
cron job as a non-privileged user do not run chakkerz Linux - General 5 06-03-2008 08:28 PM
running cron job as an ordinary user fahad26 Linux - General 1 06-30-2005 03:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 04:34 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