User avatar
silverfox0786
Posts: 215
Joined: Mon Feb 04, 2013 10:32 pm
Location: Slough, UK
Contact: Website

Crontabs not working

Sun Feb 10, 2013 1:07 pm

Im using Wheezy on my pi and crontabs worked well when i first started with it

now they dont seem to work

i use system wide crontabs via /etc/crontab file

i even tried making user crontabs with crontab -e

they dont seem to deploy does anyone know what im missing here

thanks

DBryant
Posts: 281
Joined: Sat Feb 02, 2013 12:41 pm
Location: Berkshire, UK

Re: Crontabs not working

Sun Feb 10, 2013 1:20 pm

Are you sure cron is running:
ps -lef | grep cron

Try starting it:
sudo service cron start

If there any activity in your log files to indicate a problem?

You are aware that the environment cron jobs run in is very limited? The users PATH is not available to full paths have to be specified.

You should always use crontab -e to edit files, cron is touchy about its format.

User avatar
silverfox0786
Posts: 215
Joined: Mon Feb 04, 2013 10:32 pm
Location: Slough, UK
Contact: Website

Re: Crontabs not working

Sun Feb 10, 2013 1:52 pm

DBryant wrote:Are you sure cron is running:
ps -lef | grep cron

Try starting it:
sudo service cron start

If there any activity in your log files to indicate a problem?

You are aware that the environment cron jobs run in is very limited? The users PATH is not available to full paths have to be specified.

You should always use crontab -e to edit files, cron is touchy about its format.
Here is what i have

Code: Select all

pi@raspberrypi ~ $ ps -lef | grep cron
5 S root      3568     1  0  80   0 -   955 hrtime 12:57 ?        00:00:00 /usr/sbin/cron
0 S pi        8152  8137  0  80   0 -   885 pipe_w 13:49 pts/0    00:00:00 grep --color=auto cron
pi@raspberrypi ~ $ service cron status
[ ok .] cron is running.
pi@raspberrypi ~ $ #
my crontab is this

Code: Select all

# m h  dom mon dow   command
00 00 * * * root ntpd -qg
58 05 * * * root pkill oscam
57 05 * * * root /var/script/configupdate.sh
58 05 * * * root /var/script/keyupdater.sh
59 05 * * * root /usr/local/bin/oscam -b -c /var/etc/config
*/6 * * * * root /var/script/OscamCheck.sh
05 06 * * 7 root /var/script/LogCleanUp.sh >> /var/camlogs/CleanUp.log
00 00 1 * * root rm /var/camlogs/cleanup.log
it worked before so cant understand why not now

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
Contact: Website

Re: Crontabs not working

Sun Feb 10, 2013 2:10 pm

I'd put an entry in the main crontab that runs every minute and does something nominal like appending something to a file, so its pretty quick to detemine if its working or not. Most of the entries only run once a day, when I'd be asleep. Since wheezy runs ntp as a service, the first entry may be falling over it. Its un-necessary unless you've disabled ntp, the Pi will maintain time without it.
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

DBryant
Posts: 281
Joined: Sat Feb 02, 2013 12:41 pm
Location: Berkshire, UK

Re: Crontabs not working

Sun Feb 10, 2013 2:18 pm

Can you see log in /var/log/user.log?

I've just added a 5m cronjob and see:
Feb 10 14:10:01 raspbmc CRON[12953]: (pi) CMD (/home/pi/scripts/test.sh)
Feb 10 14:10:01 raspbmc CRON[12952]: (CRON) info (No MTA installed, discarding output)
Feb 10 14:15:01 raspbmc CRON[13165]: (pi) CMD (/home/pi/scripts/test.sh)
Feb 10 14:15:01 raspbmc CRON[13164]: (CRON) info (No MTA installed, discarding output)

All fair enough, no MTA is installed.

User avatar
silverfox0786
Posts: 215
Joined: Mon Feb 04, 2013 10:32 pm
Location: Slough, UK
Contact: Website

Re: Crontabs not working

Sun Feb 10, 2013 7:00 pm

here is my log cant see any mention of crontab
Attachments
user.zip
(2.36 KiB) Downloaded 103 times

DBryant
Posts: 281
Joined: Sat Feb 02, 2013 12:41 pm
Location: Berkshire, UK

Re: Crontabs not working

Sun Feb 10, 2013 7:37 pm

Can you create a crontab entry for the pi user?

If you run a second ssh session and 'tail -f /var/log/user.log' you should be the changes made to Pi crontab.

Make sure you use 'crontab -e', comment out any existing entries and create something like:

Code: Select all

  #*/5 * * * * /home/pi/scripts/test.sh >> /home/pi/scripts/test.log
In my case, I see the following in user.log during the crontab management:
Feb 10 14:44:21 raspbmc crontab[14463]: (pi) BEGIN EDIT (pi)
Feb 10 14:44:35 raspbmc crontab[14463]: (pi) REPLACE (pi)
Feb 10 14:44:35 raspbmc crontab[14463]: (pi) END EDIT (pi)

And create the folder ~/scripts with a test.sh containing something like:

Code: Select all

#!/bin/bash
cat << END_INTRO
  ...oooOOO Test script OOOooo...
  Date: $(date)
  User: $(who am i)
  Path: ${PATH}
END_INTRO
printf "test.sh: At $(date)\n" >> ./test.log
exit 0
Don't forget these must be chmod-ed to be executable; be permissive for now and 'chmod 777 scripts/test.sh'. The script can be run from the command line; it wil ldispolay PATH. When cron runs it will also show PATH; it will be different but should run.

On the 5 minutes another entry indicating the execution of the cron job should be written in user.log.
And scripts directory will contain a file test.log; you can 'tail -f' that too and sit and watch.

I've done this and it working fine.

User avatar
silverfox0786
Posts: 215
Joined: Mon Feb 04, 2013 10:32 pm
Location: Slough, UK
Contact: Website

Re: Crontabs not working

Mon Feb 11, 2013 1:43 am

i think it must be a permission issue

having my .sh files in /var/scripts the cron dont work

but having them in /home/pi/scripts seems to work

the test script worked

need to do more digging but i think we are getting closer to getting my crons working

User avatar
silverfox0786
Posts: 215
Joined: Mon Feb 04, 2013 10:32 pm
Location: Slough, UK
Contact: Website

Re: Crontabs not working

Mon Feb 11, 2013 2:13 am

so far using the /home/pi prefix i have managed to get the sh files to deploy

now the only thing i cant get to work are the general commands

here is my crontab so far

Code: Select all

# m h  dom mon dow   command
00 00 * * * pi ntpd -qg
55 05 * * * pi pkill oscam
56 05 * * * /home/pi/scripts/configupdate.sh
57 05 * * * /home/pi/scripts/keyupdater.sh
58 05 * * * pi /usr/local/bin/oscam -b -c /var/etc/config
*/6 * * * * /home/pi/scripts/OscamCheck.sh
05 06 * * 7 /home/pi/scripts/LogCleanUp.sh >> /var/camlogs/CleanUp.log
00 00 1 * * pi rm /var/camlogs/cleanup.log
the 1st, 2nd,5th, and 8th cron dont deploy as they are commands

User avatar
rpdom
Posts: 17173
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Crontabs not working

Mon Feb 11, 2013 7:15 am

silverfox0786 wrote:the 1st, 2nd,5th, and 8th cron dont deploy as they are commands
Compare the format of these lines in your crontab with the other lines - the ones that work.

Code: Select all

55 05 * * *  pi  pkill oscam
56 05 * * *      /home/pi/scripts/configupdate.sh
Notice anything? (I've spaced them out a bit to make it easier to see).

The first line here is in the format used by the global /etc/crontab

Code: Select all

# m h dom mon dow user	command
and the second is using the format for a user crontab

Code: Select all

# m h  dom mon dow   command

User avatar
silverfox0786
Posts: 215
Joined: Mon Feb 04, 2013 10:32 pm
Location: Slough, UK
Contact: Website

Re: Crontabs not working

Mon Feb 11, 2013 12:11 pm

how would i go about settign those out into user crontabs im real confused here


thanks

User avatar
RaTTuS
Posts: 10559
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Crontabs not working

Mon Feb 11, 2013 12:20 pm

crontabs for users
login as user
crontab -e

or
sudo crontab -e -u user
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

User avatar
silverfox0786
Posts: 215
Joined: Mon Feb 04, 2013 10:32 pm
Location: Slough, UK
Contact: Website

Re: Crontabs not working

Mon Feb 11, 2013 3:49 pm

RaTTuS wrote:crontabs for users
login as user
crontab -e

or
sudo crontab -e -u user

that part im aware of

and thats where my crontabs reside

what i cant understand is the layout of the command in the cron

its not working have i written it wrong what is the unix protocol as im only used to using global crons in /etc/crontab

User avatar
rpdom
Posts: 17173
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Crontabs not working

Mon Feb 11, 2013 4:35 pm

The formats are the same - apart from user crontab should not have the userid field "pi". As it is pi's crontab it does not need to be told which user to run the command as.

So, try taking the "pi" out.

User avatar
silverfox0786
Posts: 215
Joined: Mon Feb 04, 2013 10:32 pm
Location: Slough, UK
Contact: Website

Re: Crontabs not working

Mon Feb 11, 2013 8:51 pm

i tried many different ways

i took away pi, added root removed root

i even tried with sudo infront and nothing teh cron just dont run

im really lost as to why not working

and when i installed wheezy teh first time i had /etc/crontab working perfect

i think the image is funny as i have done sudo apt-get update && upgrade in the past so it could be that

will try doing a clean install and see what that gives

d4pk
Posts: 1
Joined: Wed Feb 13, 2013 1:43 am

Re: Crontabs not working

Wed Feb 13, 2013 1:50 am

As user pi I did below & crontab for PI started working.
sudo service cron restart

my crontab
pi@raspberrypi ~/.tre $ crontab -l
37 20 * * * rm /home/pi/tre/test
16 4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22 * * * /home/pi/tre/tre.pl > /home/pi/tre/tre.out

$ vi /etc/rsyslog.conf
and uncomment the line

# cron.* /var/log/cron.log

After that, you need to restart rsyslog via
$ /etc/init.d/rsyslog restart

User avatar
silverfox0786
Posts: 215
Joined: Mon Feb 04, 2013 10:32 pm
Location: Slough, UK
Contact: Website

Re: Crontabs not working

Thu Feb 14, 2013 1:00 am

i dunno what the prob was

but i decided to reinstall raspbian wheezy and added the crontabs again to /etc/crontab and they been working perfect since

i think updatinbg a certain package breaks crontabs but having 141 packages updatabe from clean install its hard to pin point which package is breaking crontabs

michaeljquinn
Posts: 39
Joined: Sun Oct 21, 2012 8:19 am

Re: Crontabs not working

Thu Feb 14, 2013 2:09 am

Since you've reinstalled,

but I would suspect the permissions on the /var/script directory

ls -la on /var/scripts, what do you get ? (although a bit late now)

NewtownGuy
Posts: 10
Joined: Mon Feb 18, 2013 6:25 pm

Re: Crontabs not working

Mon Feb 18, 2013 6:32 pm

I have a similar problem. It looks like a permissions problem to me.

If I login as root and cd /etc/cron.hourly, I can run a script there just fine. But the script won't run automatically any more.

I don't know if this is related, but I get an error I never saw on Ubuntu 10.04, when one of these cron scripts run. The error is "<command name>: Lua: Error during loading, dofile has been disabled". It has something to do with insserv.

DBryant
Posts: 281
Joined: Sat Feb 02, 2013 12:41 pm
Location: Berkshire, UK

Re: Crontabs not working

Tue Feb 19, 2013 7:49 am

I would look closely at the environment in which the script is running; a login shell is not the same at that made available to cron jobs executed by crond.

Write a vanilla script i.e. one with no frills at all and simply dump the environment to verfiy what's going on. You may find that an existing crontab (using crontab -e) may well define the PATH which can be compared with a login session.

webpoacher
Posts: 1
Joined: Sat Apr 27, 2013 3:08 pm

Re: Crontabs not working

Sat Apr 27, 2013 3:10 pm

For all of you who are using the RaspBMC installation, you need to manually enable cron in the Program settings menu via the GUI!

wifi7878
Posts: 2
Joined: Wed Jan 15, 2014 3:15 pm

Re: Crontabs not working

Wed Jan 15, 2014 3:19 pm

Hi all !

I would like use Oscamcheck script.
I try some , but not working. :(
Please help me !

Thank You !

Regards !

DBryant
Posts: 281
Joined: Sat Feb 02, 2013 12:41 pm
Location: Berkshire, UK

Re: Crontabs not working

Wed Jan 15, 2014 4:41 pm

It would be good if you give some background to what you have installed and what measures you have already carried out to get things functioning.

For example, you could list your crontab. Have you verified that this is functioning? Have you replaced the script with something simpler to ensure that crond happily accepts your crontab entry?

wifi7878
Posts: 2
Joined: Wed Jan 15, 2014 3:15 pm

Re: Crontabs not working

Wed Jan 15, 2014 9:12 pm

My Raspberry PI is Model B with Raspbian Wheezy.
I try other crontab scripts,and this scripts is working good.
Just i not find one working oscamcheck script. :(
I need a working script.

Thank you !

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Crontabs not working

Wed Jan 15, 2014 10:26 pm

Try running it from /etc/rc.local
Or create your own /etc/init.d script that can be automatically started at system boot time. Copy /etc/init.d/skeleton to get you started with writing your own script.

I don't know why there's such a fixation with using crontab for everything. The only thing I use crontab for is a couple of tasks that run at 23:59 and 00:05 every day because they have that time dependency.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Return to “Troubleshooting”