Running CRON Jobs That Require GUI

I am using FreeFileSync utility for mirroring contents of several HDDs, call it software RAID if you must :) This software can be run in batch mode however unlike many Linux native utilities this one is not text mode by default and require more than just a terminal to run.
By any means this fact is not exceptional if you run FreeFileSync manually from some window manager, however things might not work as smoothly if you wish to run FreeFileSync at regular intervals with the help of cron for instance. That was exactly my case that I intend to describe here.

First of all I created a single script that should be called regularly by cron, the script contains all the FreeFileSync calls I need in one place. To test how the script works I added it to crontab and made it scheduled to be executed every minute:
crontab -e
cron_job_every_min
Now just to be on the safe side I restarted cron daemon:

cron_restart_and_status
Looking good, now inspecting the logs in /var/log/syslog:

cron_run_jobs

However I did not see any activity on FreeFileSync part and my disks were left unsynchronised.. What gives? What is important to know here is that cron sends you an e-mail in case it has some error to report but in order to get this mail you have to install mail server and some mail client. I went with one of the most popular choices: postfix for server with local-only configuration and mailutils package for text-based client which is called by executing mail command. Both postfix and mailutils should be available in your distro of choice, in case of Debian based flavours sudo apt-get install to the rescue!

Here is what I saw in the e-mail sent to me by cron:

mail_from_cron
It turns out the issue could be resolved with a simple trick – initialising DISPLAY variable inside the crontab itself. Here we need to remember that cron runs jobs with very limited environment and it is very common that jobs fail because of some environment variable is missing. Below I am setting the proper DISPLAY and make sure my command runs once a day instead of once per minute:

crontab_with_display
That was all I needed to successfully schedule my cron job. The takeaway is this: mind the environment working with cron, make sure to inspect syslog log and also have the local mail server properly setup in order to get mail from cron in case of issues running the jobs. By the way your inbox should be located in /var/spool/mail/ and the format of the file is human readable so maybe you won’t need mailutils, just postfix.

Sync Your Files

Was thinking about making sense of “My Documents” folder for a long time already. This folder looks like the trash can on every device I have – basically a collection of stuff that is needed and relevant, that was relevant some time ago and stuff that should have been deleted around 10 years ago..

I have copies of old document folders archived from my previous work stations and laptops – everything is unstructured and of course I won’t find a needed doc without spending hours decompressing archives and searching and searching and searching..

Finally I gathered enough determination to stop this – put everything in order and make sure this structured way of storing my important files will transcend my current workstation, laptop, tablet, you got the idea. SO there will be the same folder with important stuff on every next system without manually copying and archiving everything and for that I need some software to sync my important stuff between the devices and OSes.

This is not a review therefore I am not going to compare all the alternatives I found, this is basically a message to my future self to refresh memory on the good stuff related to files sync.

Box – good sync clients for Windows and OSX, however to get proper files sync on Android I had to use different app – Auto Box Sync because as of now Android Box app does not offer automatic files sync – you have to select what you want to upload or download manually every time.

At the time of this post Box gives you 10GB free storage which is enough for my files, there are some limits like 250 megs per 1 file but you can lift the restrictions to 5GB per file and 100GB in total storage for 10$ a month.

UPDATE (10.09.2015)
On Linux you could easily use box without Box Sync app but with WebDav. You need to install davfs2 and configure it correctly, see this link for great description.

Why not Dropbox? It gives less space for free and it syncs all folders on all devices by default or so it seems, Box gives me a possibility to select which folders to sync and which not to. I do not sync all docs on my Android devices – only part due to the space restrictions but I still have the full sync benefits because I can put a file in a folder on my PC for sharing between Android devices and this file will appear on my phone and tablet.

That is not all though – if you have your own file server with stuff you do not want to be on the cloud or the total size is too large and cloud-storing this amount is too expensive then you need an app that would be able to run in the background and periodically sync over Samba/FTP/WebDAV/etc.

There is a free app for that with a very straightforward name – FreeFileSync however for that app to work you need some additional ground work like mapping your network location to some local file system path/drive.

I decided that I do not want to be doing that and would not like to have 2 points of potential failure instead of 1 (drive mapping failure or file sync app failure instead of just file sync app potential failure) so I used commercial alternative GoodSync which is ~30$ per workstation (Win or OSX) and used Synchronize Ultimate for Android. It has some in-app purchase options, most likely I used those but do not remember the actual cost, most likely it was something like couple of EUR.

Couple of words on security for the paranoid among us – yes it is possible your stuff will be snatched from the cloud but the chance your laptop would be stolen is much higher, the same goes for your phone. The simple conclusion is that you have to encrypt your home folder where your synced files are stored and you have to encrypt the device if we are talking about Android devices.

Use BitLocker for Windows, FileVault for OSX and EncFS for Linux.

Amen.