Crontab file

Hi

I just found a /etc a crontab file with the following content:

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user    command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#

But when I run crontab - l it displays that currently no cronjob is running. Why?

If I want a new cron job do I have to change this file, i.e. add the new cron job at the end?

Moreover, there are folders cron.d, cron.daily, cron.weekly etc. For what are these folder?

13 Replies

Hi Helveticus,

As per the header of that file - that's the system crontab file.

When you 'crontab -l', you are looking at the crontab for the user you're running the command as.

As for the other subdirectories, they are called by the system crontab file, as per the entries in that file.

Hope that helps,

Sid

Thank you very much.

So if I want create a cron job, I should create a own crontab file? And where should I place that file?

Hi Helveticus,

You should be able to create a crontab for your own user by just doing 'crontab -e' (for edit). If a file does not already exist, it will create it.

You shouldn't touch the files directly, but if after you've edited it, you want to see where it is, take a look at: /var/spool/cron/crontabs.

Regards,

Sid

Thanks, it worked.

Do I have to call crontab crontab.txt at the end? Or crontab /var/spool/cron/crontabs/crontab.txt?

[edited slightly to be clearer]

Hi Helveticus,

I'm not sure how you're doing this. :)

I do:

myusername$ crontab -e
[edit my crontab file, save (no need to pick a filename) and exit]
myusername$

Then that is it - my crontab is saved, and active.

However, if I want to debug a bit further, and see that the file is created, then, as root, I do this:

# ls -l /var/spool/cron/crontabs/
total 4
-rw------- 1 myusername crontab 1089 Aug 12 14:30 myusername
#

Basically, when you do 'crontab -e', it's a wrapper around the cron system - it makes sure your file is correct before being inserted into the crontab system proper. This means that you do not need to pick a filename, the system picks it automatically for you, and then does the right thing.

I hope this makes a little more sense - you don't need to worry about the internals of cron too much to be able to write a crontab.

You don't need to know, as a user, that cron stores all user crontabs in /var/spool/cron/crontabs, it's just some internal info I provided.

Good luck!

Sid

Ok, I try it out.

# ls -l /var/spool/cron/crontabs/
total 4
-rw------- 1 myusername crontab 1089 Aug 12 14:30 myusername
#

Why do you do this command and what does "-rw–----- 1 myusername crontab 1089 Aug 12 14:30 myusername" mean?

@Helveticus:

Why do you do this command and what does "-rw–----- 1 myusername crontab 1089 Aug 12 14:30 myusername" mean?

There is no reason at all other than to show you where the file is stored. You don't need to do the 'ls' command at all - it was only for debug, I suppose.

The '-rw–---' stuff is the file listing information - permissions, owner, group, size, date modified.

For what it's worth, the file permissions of my example shows 'user = read/write, group = no access, other = no access'. But this is a whole different subject now. I found a url that might be helpful for permissions in particular: http://www.perlfect.com/articles/chmod.shtml

Thanks,

Sid

It does not work. :(

I placed the following command with nano in the crontab file (everything on one line).

*/20 * * * /usr/bin/php /home/myUsername/public/mydomain.com/public/admin/index.php -pprocessqueue -c/home/myUsername/public/mydomain.com/public/config/config.php >/dev/null

The resulting error is

"/tmp/crontab.ydA9vE/crontab":22: bad day-of-week
errors in crontab file, can't install.

You missed a "*" at the beginning.

  • Les

Thank you. Now the cronjob works but I think I have a failure in my command (it addresses phpList).

Is there an error report or log file for the cronjob?

By the way, how can I see if I have php-cli or php-cgi installed?

@Helveticus:

Thank you. Now the cronjob works but I think I have a failure in my command (it addresses phpList).

Is there an error report or log file for the cronjob?

Virtually everything gets logged to /var/log/syslog, including cron. I have yet to find a log specific to cron, however you should be able to see the problem if you check syslog immediately after the cron job executes.

@Helveticus:

By the way, how can I see if I have php-cli or php-cgi installed?

Check your distro's package manager.

(somehow my post got duplicated)

Thank you so much. Now with php-cgi everything works fine.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct