pfSense Support Subscription

Author Topic: Cron not working?  (Read 12205 times)

0 Members and 1 Guest are viewing this topic.

Offline jlepthien

  • Hero Member
  • *****
  • Posts: 657
  • Karma: +0/-0
    • View Profile
Cron not working?
« on: January 04, 2010, 02:09:11 am »
Hi there,

I added a job using the crontab -e command as root. The jobs do not get executed. Why is that?
If I run the command manually, everything is fine...
| apple fanboy | music lover | network and security specialist | in love with cisco systems |

Offline jlepthien

  • Hero Member
  • *****
  • Posts: 657
  • Karma: +0/-0
    • View Profile
Re: Cron not working?
« Reply #1 on: January 04, 2010, 08:38:49 am »
Is there any other way besides downloading the config, editing it, uploading it again and rebooting the device?
| apple fanboy | music lover | network and security specialist | in love with cisco systems |

Offline jlepthien

  • Hero Member
  • *****
  • Posts: 657
  • Karma: +0/-0
    • View Profile
Re: Cron not working?
« Reply #2 on: January 07, 2010, 03:36:36 am »
Any1?
| apple fanboy | music lover | network and security specialist | in love with cisco systems |

Offline _igor_

  • Hero Member
  • *****
  • Posts: 615
  • Karma: +2/-0
    • View Profile
Re: Cron not working?
« Reply #3 on: January 07, 2010, 11:43:38 am »
You'r right. I have a job in which isn't executed too. Looks like an error. System-cronjobs are executed.
Is it failure of the cron-package or system-error?

Offline cmb

  • Hero Member
  • *****
  • Posts: 11230
  • Karma: +891/-7
    • View Profile
    • Chris Buechler
Re: Cron not working?
« Reply #4 on: January 10, 2010, 01:03:35 am »
You can't edit crontab to add jobs. Put them in the config.

Offline jimp

  • Administrator
  • Hero Member
  • *****
  • Posts: 20797
  • Karma: +1311/-24
    • View Profile
Re: Cron not working?
« Reply #5 on: January 10, 2010, 05:10:14 pm »
You can also install the Cron package which gives you a nice gui to maintain the cron jobs (system and user added ones)
Need help fast? Commercial Support!

Co-Author of pfSense: The Definitive Guide. - Check the Doc Wiki for FAQs.

Do not PM for help!

Offline _igor_

  • Hero Member
  • *****
  • Posts: 615
  • Karma: +2/-0
    • View Profile
Re: Cron not working?
« Reply #6 on: January 10, 2010, 05:34:47 pm »
I'm having the cron-package installed and my cronjob is in the config.xml, but not executed. MAnually it works great, but not automatic.

Offline jimp

  • Administrator
  • Hero Member
  • *****
  • Posts: 20797
  • Karma: +1311/-24
    • View Profile
Re: Cron not working?
« Reply #7 on: January 10, 2010, 05:38:55 pm »
The most common other error with scripts that don't work in cron is not using full paths to all files and programs being used.

The way cron scripts are executed they don't inherit much of any environment settings, especially PATH, so if you run something such as "grep" in a cron script you really need to use "/usr/bin/grep" instead.
Need help fast? Commercial Support!

Co-Author of pfSense: The Definitive Guide. - Check the Doc Wiki for FAQs.

Do not PM for help!

Offline _igor_

  • Hero Member
  • *****
  • Posts: 615
  • Karma: +2/-0
    • View Profile
Re: Cron not working?
« Reply #8 on: January 11, 2010, 05:15:38 am »
I know about this problems, and my script is calles directly with full path. The script itself uses full path all time. No indirect references used. So this errors are not possible. Calling the script via console works great.

Offline Perry

  • Hero Member
  • *****
  • Posts: 1152
  • Karma: +1/-0
    • View Profile
Re: Cron not working?
« Reply #9 on: January 11, 2010, 08:42:08 am »
Missing execute bit on the script?
/Perry
doc.pfsense.org

Offline jimp

  • Administrator
  • Hero Member
  • *****
  • Posts: 20797
  • Karma: +1311/-24
    • View Profile
Re: Cron not working?
« Reply #10 on: January 11, 2010, 09:00:25 am »
I know about this problems, and my script is calles directly with full path. The script itself uses full path all time. No indirect references used. So this errors are not possible. Calling the script via console works great.

I suggest you check your script again, or if it's something you can share, post it so others can try.

I just verified that a basic script does, in fact, work with cron for me on a 2.0 box.

# cat test.sh
#!/bin/sh   
/bin/echo blah >> /tmp/blah.txt

# chmod a+x test.sh
# ./test.sh
# cat /tmp/blah.txt
blah
#


Add cron job via Cron package GUI:
*/1       *       *       *       *       root       /root/test.sh 

wait... wait... wait...

# cat /tmp/blah.txt
blah
blah
blah
Need help fast? Commercial Support!

Co-Author of pfSense: The Definitive Guide. - Check the Doc Wiki for FAQs.

Do not PM for help!

Offline jlepthien

  • Hero Member
  • *****
  • Posts: 657
  • Karma: +0/-0
    • View Profile
Re: Cron not working?
« Reply #11 on: May 05, 2010, 10:07:06 am »
Hi,

I have a cron job which is not executed in the build 05/04/10 of 2.0....

30   *   *   *   *   root   /usr/bin/nice -n20 /etc/rc.conf_mount_rw ; /usr/bin/tar -czf /cf/conf/rrd.tgz -C /var/db/rrd/*.rrd ; /etc/rc.conf_mount_ro

This line actually does work with my 1.2.3 install but not in 2.0

Any info?
| apple fanboy | music lover | network and security specialist | in love with cisco systems |

Offline jimp

  • Administrator
  • Hero Member
  • *****
  • Posts: 20797
  • Karma: +1311/-24
    • View Profile
Re: Cron not working?
« Reply #12 on: May 05, 2010, 05:21:24 pm »
Does the same line work as-is if you run it from the shell?
Need help fast? Commercial Support!

Co-Author of pfSense: The Definitive Guide. - Check the Doc Wiki for FAQs.

Do not PM for help!

Offline jlepthien

  • Hero Member
  • *****
  • Posts: 657
  • Karma: +0/-0
    • View Profile
Re: Cron not working?
« Reply #13 on: May 05, 2010, 05:43:32 pm »
Yep. Works from shell. 
| apple fanboy | music lover | network and security specialist | in love with cisco systems |

Offline jimp

  • Administrator
  • Hero Member
  • *****
  • Posts: 20797
  • Karma: +1311/-24
    • View Profile
Re: Cron not working?
« Reply #14 on: May 05, 2010, 06:45:18 pm »
Did you add this via the cron package, or manually into the config file?

I wonder if the job is making it into the actual crontab file.
Need help fast? Commercial Support!

Co-Author of pfSense: The Definitive Guide. - Check the Doc Wiki for FAQs.

Do not PM for help!