• Currently using VMware at work? We want to hear from you.

    Thinking of making a switch from VMware? We'd love to hear your thoughts and feedback about which hypervisor you have been researching or already using. Click here to vote and share your thoughts! You can vote HERE!

How do you get your cron job to run?

Status
Not open for further replies.

codenamezero

Explorer
Joined
Sep 4, 2011
Messages
59
SOLVED: How do you get your cron job to run?

I wrote a script that could remove completed torrent from Transmission, but i couldn't get cron to run the job...

So I ran this to see what job the root is running but...
Code:
freenas# crontab -u root -l
crontab: no crontab for root


I open up the crontab, there are clearly a couple of cron job under root, but not sure why is not being set... I added the following entry, tried restarting cron, reboot, nothing.

Code:
freenas# vi /etc/crontab
# Remove completed torrent from Transmission
*/5     *       *       *       *       root    /mnt/FREENAS/torrent/bin/remove_completed


Could anyone tell me how you added your own cron job?
 

pallfreeman

Dabbler
Joined
Sep 1, 2011
Messages
38
Try editing /conf/base/etc/crontab instead of /etc/crontab, and then rebooting.
 

Durkatlon

Patron
Joined
Aug 19, 2011
Messages
414
There's a GUI method for adding cron jobs. It leaves a little bit of a mess in the crontab file because it doesn't recognize when it should use "*" instead of enumerating valid value (like for months of the year for instance). But it works fine for kicking off crons.
 

Tekkie

Patron
Joined
May 31, 2011
Messages
352
Edits to the crontab file will be lost on the reboot as these are overwritten by the FreeNAS8 DB settings anyway so that won't work either way, use the UI as suggested for this if you want the changes to persist.
 

pallfreeman

Dabbler
Joined
Sep 1, 2011
Messages
38
Oh bum.

That's something else I have to document for my potential users instead of doing it for them in my install scripts.
 

codenamezero

Explorer
Joined
Sep 4, 2011
Messages
59
I am not running the RC version, just the official release of 8.0, so it doesn't have the GUI crontab function yet. So I partially got it "working", in order to get the changes stick, i need to edit /conf/base/etc/crontab

However, that doesn't solve the problem, it looks like it won't load any crontab for root.

I looked at the /conf/base/etc/rc.d/cron and is running cron with -s flag, whatever that is, is not documented anywhere, and i have no idea what it is doing... maybe s stands for suppress?

Still need to find out how to get cron to load the crontab... right now is not loading for any user at all.
 

codenamezero

Explorer
Joined
Sep 4, 2011
Messages
59
Alright, I got the crontab loaded automatically, BUT THE DARN THING IS NOT RUNNING IT! WTF?

So this is my crontab file for root:
Code:
#
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
# Remove completed torrent from Transmission
*/5     *       *       *       *       root    /mnt/FREENAS/torrent/bin/rm_completed_bt.sh


To get the crontab running, you need to put your crontab file in the following location:
/conf/base/var/cron/tabs

So for example:
cp /mnt/FREENAS/torrent/bin/crontab /conf/base/var/cron/tabs/root
where root is the filename

You need to name it as the user that will run those cron jobs... after that you can reboot. After you rebooted, you will see the crontab being loaded automatically:

Code:
Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994
        The Regents of the University of California.  All rights reserved.

FreeBSD 8.2-RELEASE-p1 (FREENAS.amd64) #4: Sat Apr 30 10:39:46 PDT 2011

        FreeNAS nanobsd (c) 2009-2010, The FreeNAS Development Team
        All rights reserved.
        FreeNAS is under the modified BSD license.

        For more information, documentation, help or support, go here:
        http://freenas.org
Welcome to FreeNAS

freenas# crontab -l
#
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
# Remove completed torrent from Transmission
*/5     *       *       *       *       root    /mnt/FREENAS/torrent/bin/rm_completed_bt.sh
freenas#


BUT, THE DARN THING IS STILL NOT BRING EXECUTED WTF :P

If I execute the script on its own, it works... So i'm sure my script works.

Code:
freenas# /mnt/FREENAS/torrent/bin/rm_completed_bt.sh
Removing torrent ID#    1 [UTW]_Appleseed_XIII_-_02_[BD][h264-720p_FLAC][E8D09710].mkv
localhost:9091 responded: "success"
 

Tekkie

Patron
Joined
May 31, 2011
Messages
352
Oh bum.

That's something else I have to document for my potential users instead of doing it for them in my install scripts.
Read the docs beforehand ;) :P
 

Tekkie

Patron
Joined
May 31, 2011
Messages
352
@code

take seat wait a few more days (weeks) until 8.0.1 is released and all will be good ;) no hacking around the system for crontab.
 

pallfreeman

Dabbler
Joined
Sep 1, 2011
Messages
38
I looked at the /conf/base/etc/rc.d/cron and is running cron with -s flag, whatever that is, is not documented anywhere, and i have no idea what it is doing... maybe s stands for suppress?

Nah, it's something to do with special handing of DST, so your cron jobs don't get screwed up when "the hour changes". All my FreeBSD servers are using it; it's in the man page.
 

codenamezero

Explorer
Joined
Sep 4, 2011
Messages
59
@code

take seat wait a few more days (weeks) until 8.0.1 is released and all will be good ;) no hacking around the system for crontab.

Well, it won't hurt to learn how to do it either. I like learning stuff. :) I'm so close to get it working anyway. Is not hacking around the system, cron is suppose to be part of a basic feature in FreeBSD anyway no? Plus i might just stick with 8.0 and not upgrade if i could get this cron job working. It would be nice if one of you expert could chime in to solve the mystery.

Nah, it's something to do with special handing of DST, so your cron jobs don't get screwed up when "the hour changes". All my FreeBSD servers are using it; it's in the man page.

Ah thanks for the info, i looked up a couple of cron man page from google, didn't show the -s. Good to know.
 

codenamezero

Explorer
Joined
Sep 4, 2011
Messages
59
Alright, after playing around with it for another 2 hours, i finally got it resolved.

Basically you need to edit /conf/base/var/tab/root
However, the syntax is a little different, you don't need to specify the username...

Here is what I have in my root's crontab file, again, you need to edit /conf/base/var/tab/root
Code:
#
# $FreeBSD: src/etc/crontab,v 1.33.2.1 2009/08/03 08:13:06 kensmith Exp $
#
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/mnt/FREENAS/torrent/bin
# Remove completed torrent from Transmission
*/30    *       *       *       *       rm_completed_bt.sh >> /mnt/FREENAS/torrent/bin/cron.log 2>>&1


Save and reboot.

PS: Stuff inside /conf/base/etc/crontab is irrelevant, i tried editing the entries in there, doesn't do anything.
 
Status
Not open for further replies.
Top