You are not logged in.

#1 2010-10-11 11:32:57

flytwokites
Member
Registered: 2008-12-04
Posts: 14

[SOLVED] cron file format for /etc/cron.d/

when I create a file in /etc/cron.d/:

05 19 * * * wjzhou echo "OK?" >/tmp/cron-is-ok

When time is due, a file 'cron-is-ok' created, but owner is 'root', not 'wjzhou',
it seems this job does not run as user 'wjzhou', then I check /var/log/crond.log:

Oct 11 19:05:01 localhost crond[10480]: FILE /etc/cron.d/test USER root PID 10487 wjzhou echo "OK?" >/tmp/cron-is-ok
Oct 11 19:05:01 localhost crond[10480]: exit status 127 from user root wjzhou echo "OK?" >/tmp/cron-is-ok
Oct 11 19:05:01 localhost crond[10489]: mailing cron output for user root wjzhou echo "OK?" >/tmp/cron-is-ok

How to run a cron job as a specific user use dir /etc/cron.d?

Last edited by flytwokites (2010-10-12 13:46:55)

Offline

#2 2010-10-11 11:38:01

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] cron file format for /etc/cron.d/

Run

crontab -l

when logged as wjzhou.

[karol@black ~]$ crontab -l
no crontab for karol
man crontab

for details.

Last edited by karol (2010-10-11 11:39:36)

Offline

#3 2010-10-11 13:03:19

flytwokites
Member
Registered: 2008-12-04
Posts: 14

Re: [SOLVED] cron file format for /etc/cron.d/

I check the book 'Linux Administration HandBook':
http://books.google.com/books?id=GB_O89 … 22&f=false

minute hour day month weekday [username] command

The format of job in /etc/cron.d is different to per user job, it has a 'username' field, but dcron seems ignore
this field.
Is dcron actually not implemented this feature?

Offline

#4 2010-10-11 13:58:30

jdarnold
Member
From: Medford MA USA
Registered: 2009-12-15
Posts: 485
Website

Re: [SOLVED] cron file format for /etc/cron.d/

I'm not so sure about the [username] field. I don't see it documented in crontab's manpage even. It may be an archaic way of doing it, as the current way is for each user to have their own crontab.

Offline

#5 2010-10-11 14:38:29

igndenok
Member
From: Sidoarjo, Indonesia
Registered: 2010-06-07
Posts: 160

Re: [SOLVED] cron file format for /etc/cron.d/

Why not create cron job with

$ crontab -e

instead create file under /etc/cron.d


Ask, and it shall be given you.
Seek, and ye shall find.
Knock, and it shall be opened unto you.

Offline

#6 2010-10-12 07:31:31

flytwokites
Member
Registered: 2008-12-04
Posts: 14

Re: [SOLVED] cron file format for /etc/cron.d/

igndenok wrote:

Why not create cron job with

$ crontab -e

instead create file under /etc/cron.d

Because I want to write a bash script to add a cron job for an user and do not override that user's existing jobs.

Offline

#7 2010-10-12 08:43:19

Ramses de Norre
Member
From: Leuven - Belgium
Registered: 2007-03-27
Posts: 1,289

Re: [SOLVED] cron file format for /etc/cron.d/

You could use "sudo -u [username]".

Offline

#8 2010-10-12 13:46:17

flytwokites
Member
Registered: 2008-12-04
Posts: 14

Re: [SOLVED] cron file format for /etc/cron.d/

Thinks for your answers.
It is worked with create file under /etc/cron.d and use this format:

45 21 * * * su -c "<command>" -s /bin/bash <username>

Offline

Board footer

Powered by FluxBB