Category Archives: Raspberry Pi / Raspbmc

Some snippets i found worth sharing during tinkering with my little raspberry pi!

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 /dns_update.sh
    Every hour at minute xx:20 and xx:40 the dns_update.sh 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

Change Audiooutput mode and other settings in Raspbmc via FTP / SSH / command line

As i couldn’t find a proper guide to editing the settings of the raspbmc os via command line/ssh or ftp, here are my findings about it. As I’m pretty new to linux, there may be some faster / more efficient ways to do this (e.g. editing the setting files via nano/vi or even writing scripts to change certain settings) but for me the following works pretty well as for now. If you have some addition / comment please share them in the section below or contact me elsewhere, tia!

If you’re new to raspbmc the FAQ in the official wiki are definitely worth checking out. Here you find the default logon information (user: pi – pw: raspberry), the commands to stop and start xbmc (used in this guide) and many other interesting infos.

  1. Connect to your raspberry pi via FTP and/or SSH (i use FileZilla and the Mac OSX Terminal to do this – any other ftp/ssh client will also do)
  2. Navigate to /home/<username (default ‘pi’)>/.xbmc/userdata/guisettings.xml and open or download it. As you can see in the screenshot, I use Filezilla’s context menu to ‘View/Edit’ the remote file in my default text editor.
    Screen Shot 2013-03-30 at 2.18.21 PM
  3.  Look for the <mode> tag inside <audiooutput> tag or any other setting you want to change and change it to the value you need. For switching audio modes see the screenshot below.
    Screen Shot 2013-03-30 at 2.20.20 PM
  4. Save the settings file. Filezilla automatically detects changes to the local file and offers to upload the changed file – you can also delete the local copy in the process.
    Screen Shot 2013-03-30 at 2.20.45 PM
  5. Restart xbmc via SSH to apply the changes to your running raspberry pi – using the commands found in the FAQ mentioned above.
    Screen Shot 2013-03-30 at 2.21.42 PM

This already concludes my little guide for changing settings in raspbmc. For preferences set in the raspbmc settings addon, access the file /home/<your_username>/.xbmc/userdata/addon_data/script.raspbmc.settings/settings.xml – other than that the process is the same. Hope this helps someone – I’d be happy about every kind of feedback. Have a nice day! 🙂

Update (28.06.2013):
Good news everyone! 🙂 Starting with the June Update of the Raspbmc System we are able to output audio both to HDMI AND the analog output! This is especially useful if you also want to use your raspberry (eg. play music via airplay like I do) when your TV/monitor is switched of. I’m glad the creator(s) of raspbmc made my guide obsolete 😛

So as a quick summary, we now have the following audio output modes (<mode>x</mode>):

  • 0 – analog
  • 2 – HDMI
  • 3 – All outputs

This is really great, thanks a lot to the raspbmc guy(s) for improving our experience even further! For more info about the june update of Raspbmc go here.