Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
 Post subject: Crontab file
PostPosted: Mon Aug 12, 2013 8:13 am 
Offline
Junior Member

Joined: Wed Jul 31, 2013 3:58 am
Posts: 29
Hi

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

Code:
# /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?


Top
   
 Post subject: Re: Crontab file
PostPosted: Mon Aug 12, 2013 9:03 am 
Offline
Senior Newbie

Joined: Mon Aug 12, 2013 8:58 am
Posts: 14
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


Top
   
 Post subject: Re: Crontab file
PostPosted: Mon Aug 12, 2013 9:08 am 
Offline
Junior Member

Joined: Wed Jul 31, 2013 3:58 am
Posts: 29
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?


Top
   
 Post subject: Re: Crontab file
PostPosted: Mon Aug 12, 2013 9:23 am 
Offline
Senior Newbie

Joined: Mon Aug 12, 2013 8:58 am
Posts: 14
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


Top
   
 Post subject: Re: Crontab file
PostPosted: Mon Aug 12, 2013 9:28 am 
Offline
Junior Member

Joined: Wed Jul 31, 2013 3:58 am
Posts: 29
Thanks, it worked.

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


Top
   
 Post subject: Re: Crontab file
PostPosted: Mon Aug 12, 2013 9:36 am 
Offline
Senior Newbie

Joined: Mon Aug 12, 2013 8:58 am
Posts: 14
[edited slightly to be clearer]

Hi Helveticus,

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

I do:
Code:
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:

Code:
# 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


Top
   
 Post subject: Re: Crontab file
PostPosted: Mon Aug 12, 2013 9:40 am 
Offline
Junior Member

Joined: Wed Jul 31, 2013 3:58 am
Posts: 29
Ok, I try it out.

Code:
# 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?


Top
   
 Post subject: Re: Crontab file
PostPosted: Mon Aug 12, 2013 9:48 am 
Offline
Senior Newbie

Joined: Mon Aug 12, 2013 8:58 am
Posts: 14
Helveticus wrote:
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


Top
   
 Post subject: Re: Crontab file
PostPosted: Mon Aug 12, 2013 10:58 am 
Offline
Junior Member

Joined: Wed Jul 31, 2013 3:58 am
Posts: 29
It does not work. :(

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

Code:
*/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

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


Top
   
 Post subject: Re: Crontab file
PostPosted: Mon Aug 12, 2013 11:03 am 
Offline
Senior Member

Joined: Mon Jul 05, 2010 5:13 pm
Posts: 392
You missed a "*" at the beginning.

- Les


Top
   
 Post subject: Re: Crontab file
PostPosted: Mon Aug 12, 2013 11:50 am 
Offline
Junior Member

Joined: Wed Jul 31, 2013 3:58 am
Posts: 29
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?


Top
   
 Post subject: Re: Crontab file
PostPosted: Mon Aug 12, 2013 12:12 pm 
Offline
Senior Member
User avatar

Joined: Thu Jun 16, 2011 8:24 am
Posts: 412
Location: Cyberspace
Helveticus wrote:
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 wrote:
By the way, how can I see if I have php-cli or php-cgi installed?


Check your distro's package manager.

_________________
Kris the Piki Geeker


Last edited by Piki on Mon Aug 12, 2013 12:14 pm, edited 1 time in total.

Top
   
 Post subject: Re: Crontab file
PostPosted: Mon Aug 12, 2013 12:12 pm 
Offline
Senior Member
User avatar

Joined: Thu Jun 16, 2011 8:24 am
Posts: 412
Location: Cyberspace
(somehow my post got duplicated)

_________________
Kris the Piki Geeker


Top
   
 Post subject: Re: Crontab file
PostPosted: Mon Aug 12, 2013 12:52 pm 
Offline
Junior Member

Joined: Wed Jul 31, 2013 3:58 am
Posts: 29
Thank you so much. Now with php-cgi everything works fine.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group