# Crontab problem



## tinusb (Dec 30, 2009)

Hi all! 

I've got a serious issue.

I've got a FreeBSD installation, but for some reason, the cron jobs does not run.

---
Crontab:


```
server# crontab -l
08 15 * * * /usr/home/sunbirdtours/scripts/startmaintenance.sh
server#
```
---

---
dmesg:


```
FreeBSD 7.2-RELEASE #0: Fri May  1 08:49:13 UTC 2009
    [email]root@walker.cse.buffalo.edu[/email]:/usr/obj/usr/src/sys/GENERIC
```
---

---
startmaintenance.sh:


```
server# ll /usr/home/sunbirdtours/scripts/startmaintenance.sh
-rwxrwxrwx  1 root  sunbirdtours  4637 Nov 26 07:09 /usr/home/sunbirdtours/scripts/startmaintenance.sh
server#
```
---


As you can see, it's definately not a rights issue. I did destroy the crontab and recreated it, but still to no avail. The cron job does not even indicate when running 'ps -aux | grep cron'

Any, and all help will be appreciated!

Thank you
Tinus


----------



## sixtydoses (Dec 30, 2009)

Start cron by running the following command:


```
/etc/rc.d/cron start
```


----------



## DutchDaemon (Dec 30, 2009)

3:08 PM is a rather precise, but strange time to run a scheduled job..


----------



## sixtydoses (Dec 30, 2009)

DutchDaemon said:
			
		

> 3:08 PM is a rather precise, but strange time to run a scheduled job..



Oh.. so prolly he waited the job to run at 08:15 am.

@tinusb- Did you?


----------



## tinusb (Dec 30, 2009)

Hi all! LOL yeah saw the problem. Anyway, did restart cron with '/etc/rc.d/cron restart', and this was the output:

----

```
server# ps -aux | grep cron
root      54040  0.0  0.0  3212  1044  ??  Ss    8:59AM   0:00.00 /usr/sbin/cron -s
root      63592  0.0  0.0  3212  1156  ??  I     9:02AM   0:00.00 cron: running job (cron)
root      76601  0.0  0.0  1660   884  p0  RL+   9:04AM   0:00.00 grep cron
server# ps -aux | grep cron
root      54040  0.0  0.0  3212  1044  ??  Ss    8:59AM   0:00.00 /usr/sbin/cron -s
root      78331  0.0  0.0  3336   968  p0  R+    9:04AM   0:00.00 grep cron
server# date
Wed Dec 30 09:04:36 WAST 2009
```
---

I did change the schedule to '02 09'. The total time for the maintenance.sh script should be in the region of about 20 minutes, as it is a script that scans 3 directories for virusses, etc. etc. etc. --- but as you can see, it 'lasted' less than 3 minutes, and none of the emails it's supposed to send, was sent out.

I did chown the script file to 'root:wheel', and even that didn't help.

If I run the script manually, everything works 100%.

This is the WEIRDEST problem ever!

Thank you again for all the help all!


----------



## DutchDaemon (Dec 30, 2009)

Try using _full paths_ for all commands in that script. Cron has a very limited path, and when a script runs from the command-line, but not from cron, insufficient path settings are almost always to blame.

You can also extend cron's path by putting this as the first line in the crontab:


```
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
```

This is usually sufficient to find executables that were installed by ports or packages as well.


----------



## tinusb (Dec 30, 2009)

DutchDaemon,

Thank you thank you thank you! It's finally working  

Have a great day!
Tinus


----------



## pcbsd64 (Mar 23, 2011)

*I too am having difficulty getting my crontab to run*


```
[chris@pcbsd64] ~> crontab fetch
[chris@pcbsd64] ~> crontab -l
PATH=/usr/local/bin
*/1 *   *   *   * /usr/local/bin/fetchmail[chris@pcbsd64] ~> /etc/rc.d/cron start
eval: cannot open /var/run/cron.pid: Permission denied
Starting cron.
cron: can't open or create /var/run/cron.pid: Permission denied
/etc/rc.d/cron: WARNING: failed to start cron
[chris@pcbsd64] ~> sudo /etc/rc.d/cron start
cron already running? (pid=1967).
[chris@pcbsd64] ~>
```

Is this a permission problem? I couldn't find anything in the handbook about configuring cron.pid permissions.


----------



## wblock@ (Mar 23, 2011)

A. cron is enabled by default.  It's already running.  You have to be root to start or restart it.
B. Make sure your files have a linefeed after the final line.  Many things will ignore that line otherwise.
C. You're responding to a year-old thread.  Starting a new one with a more specific title might get better responses.


----------



## pcbsd64 (Mar 24, 2011)

Thanks wblock. If your advice doesn't work, I will start a new thread. In the mean time this works for me in lieu of my crontab file:

```
#!/bin/sh
while :
do
sleep 60 && /usr/local/bin/fetchmail
done
```
I saved this script and run it as part of my /.config/openbox/autostart.sh

I think I will start a new thread anyway so your advice can benefit current viewers.


----------

