Running cron jobs on Raspberry Pi in Raspbmc

Here’s another little tutorial especially for people new to raspberry pi or linux in general (such as myself). Cron jobs are used to execute specific actions at pre-configured times. These actions can be executing scripts, writing data to a file, etc. (would be glad to hear of stuff you do with cron jobs in the comment section ;))

In my specific case I needed a script to map my changing external ip address at home to the domain I specified for my raspberry to have access to it when I’m away. Big thanks for all the help to my good friend Thomas for domain hosting and tipps on how to get this to work! Now let’s get to it!

  1. Activate cron jobs in Raspbmc
    Per default running cron jobs is deactivated in Raspbmc and there are two ways to activate them.
    – In the Raspbmc GUI under Programs -> Raspbmc Settings -> System Configuration -> Service Management -> Cronjob Scheduler
    – Via SSH/FTP by modifying sys.service.cron value to “true” the settings file under /home/<your_username>/.xbmc/userdata/addon_data/script.raspbmc.settings/settings.xml – for more infos on changing settings via SSH / FTP, check my latest blog post
  2. Configure your ‘crontab’
    All cron jobs are defined in this file and you can specify multiple of them, each on its own line – to edit  your crontab in your default text editor, type ~$ crontab -e in the console. By using ~$ crontab -l the content is shown.
  3. Write your cronjob
    The syntax isn’t too easy to understand in the beginning, but there are tools online, which can help you write your (first) cron jobs. In my case the cron job looks like this:
    20,40 * * * * sh /
    Every hour at minute xx:20 and xx:40 the script in the root directory of my raspberry is executed, which just calls a magic dns mapping domain via wget.
    Especially in the beginning it’s a good idea to add a test job, which executes every minute and only helps to see if your cron configuration is set up properly. I use the following:
    * * * * * echo “crontest $(date) $(whoami)” >> /tmp/crontest.txt
    This just writes the current date and the current user to the specified textfile.
    Below is a screenshot of my current crontab:
    Screen Shot 2013-04-05 at 11.48.22 PM
  4. Control the cron service
    In order to get your cron jobs to run, the cron service must be active. The following commands let you control the cron service:
    ~$ /etc/init.d/cron stop
    ~$ /etc/init.d/cron start
    ~$ /etc/init.d/cron restart
    These commands will probably need a leading ‘sudo‘ – just check your console output. To quickly repeat your last command with leading sudo type ‘sudo !!‘.
  5. Check if your cron jobs are running
    If you also specified a test cron job like the one above, you can test if it’s working by printing the latest contents of the text file to your console. This can be done by using the ‘tail’ command and the ‘-f‘ parameter updates the output as new content is added to the file. See below screenshot for example output:
    Screen Shot 2013-04-06 at 12.00.48 AM

And… That’s it! Thanks for reading, hope it helps someone, glad for every kind of feedback! Bye!

Update (10.11.2013): As jazz and CFWhitman pointed out in the comment section, you can also just use the commands /etc/init.d/cron status or service cron status to check if cron jobs are running. For output see screenshot below 🙂 Thanks!

Screenshot 2013-11-10 04.31.52

28 thoughts on “Running cron jobs on Raspberry Pi in Raspbmc

  1. Beverley Guide

    Thanks for the information here. i found it really useful for fixing my cron problems.

  2. Pingback: How can I keep my Raspbian "Wheezy" up to date? | DL-UAT

  3. Geronimo

    Hi Philipp, thanks for the detailed manual for creating a cronjob. I came here because I was searching this, duh. But I was also planning to use cronjobs for posting my external IP to my external domain hosting, through ftp. That way I can access the ssh, websites, etc through my hosting. Would you care to share your python script for doing so?
    Kind regards

    1. wexoo Post author

      Hi Geronimo,
      glad you liked the tutorial and sorry for my late reply. Regarding my script – it was just a simple sh script calling an url via wget, which did the mapping of the ip addresses. It won’t really help you in any way I’m afraid 🙁 The url was something like that ‘’ and I got it from a friend of mine, which manages all my hosting needs 🙂 You’ll have to see if your hoster offers some solution like that I am afraid. Good luck!

  4. Mayki

    please advice if you enter the command manually “sudo /home/pi/” works. If you enter it into the cron “5 12 * * * /home/pi/” does not correctly. Where is my mistake?

    1. wexoo Post author

      Hi Mayki,
      I don’t have too much time right now to check this, but it could be a permission issue. Maybe the cron service (running user) doesn’t have enough permissions to execute the file. I’m a linux beginner so I can’t give you more details, but you can find many articles online about the permission system. Let me know if you still have problems and I’ll try to look more into it in the coming days 🙂

  5. Pingback: Reverse Tunnels and RaspBMC | Neave Engineering

  6. Jack Davison

    Can you automate a command line “tightvncserver” in the cron restarter, and if so how?

    1. wexoo Post author

      Hi Jack, I personally don’t know anything about tightvnc server, but I guess if it runs as a linux service, there’s no reason why you shouldn’t be able to restart it via cron 🙂 Just select the interval you see fit (probably with the help of this ) and paste in the command to restart or start it. The Raspberry Pi normally should keep cron enabled even if you restart it or shut it down, so cron just starts running again when booted. If you still have problems, I could look more into it, if you post a bit more info about your setup 😉
      Cheers, wexoo

  7. mynameishidden

    I dont have yet my Pi, but i order soon. How can i run php script with cron?

  8. Kgeebelen

    Somewhere an hour before the date I took one Levitra 20mg pill. After half an hour I wanted to go to the toilet, just touched my penis and it started growing. At the same time I did not have any excitement and it seemed to me that I somehow feel bad. Thanks to the Canadian online pharmacy I have a good hard erection from just one glance at my sexual partner.

  9. Kgeebelen


    Thanks, helped me out a lot!

    I’m using cron on my Pi to execute a python script every 15 minutes. The script fetches the mail from a gmail-account I created, downloads the attachments to a certain directory and then removes the read e-mails. Very helpful for sending stuff to my Pi from wherever I am, since I’m not able to provide access to it when I’m not at home..

    1. wexoo Post author

      Nice! Glad it helped! Someday I really wanna learn some scripting languages as well – at least so much that I know what’s possible with ’em 🙂

    2. dale

      ive been looking for a way to do that (save attachments off to a directory), would you be willing to share your py script?


    Thank you for this very clear explanation of cron! I’ve now got cron working on raspbmc, and I’ve learned a few new commands. 🙂

  11. Pingback: Monitoring a Growatt PV inverter using Raspberry Pi | sisand

  12. Danie

    On my pi the cronscheduler option is missing in the gui.
    When looking by ssh the settings file is also missing.

    Do I have to add an addon first?

    1. wexoo Post author

      Hi Danie! It should be in the “Raspbmc Settings”-addon under Programs in the homescreen of Raspbmc. It is an addon but it should be installed in every raspbmc installation. I’ve not yet updated to the most recent version of raspbmc – maybe there were some changes to that logic – i’ll reply again, when my raspberry is up-to-date 🙂

    2. wexoo Post author

      Hi again, just updated my raspberry to the latest version of raspbmc – the settings addon is still there. It’s in the same menu item/”tab” (Programs) where you can also find the newly added browser.

      Also checked the ssh option – should still work as well. The default username/password for a new raspbmc install is pi/raspberry. This default user should see the file (via SSH or FTP).

      1. wexoo Post author

        Thanks, just tried them both – work like a charm! The latter also shows the process id of the cron job, which is the only difference i can see. Included in the post now. Cheers!

  13. Thiago

    Hey Thanks!! Makes a lot of sense enable cron service via SSH. Everybody says to do that via XBMC. I’m away from my TV so how can I do?? SSH saves the day once again…
    Thanks man. Help me a lot…

    1. wexoo Post author

      Thanks for your kind words! 🙂 Hehe, yeah I always try to find both ways, as sometimes I don’t wanna switch on my TV just to make a simple setting’s change, especially if I’m already in a console session on it. Definitely good to know your possibilities 😉 Glad you enjoyed it!

      PS: Sorry for replying so late, but I didn’t get a mail notification – gotta look into that matter 🙂


Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.