Tip - alternative for gnome-schedule on Linux

Get help for specific problems
tmountney
Posts: 5
Joined: 23 May 2019

Post by tmountney • 02 Jun 2019, 16:39

gnome-schedule (GS) is not available as a package with Debian - not sure if this is true for all Debian based distros. GS was removed from Debian December 2015 with version 2.1.1-4.

I have a workaround to eliminate the use of gnome-schedule (GS) and the "X application" option to create a task schedule.

It requires using a script rather than directly scheduling the FFS batch. I've been testing this for 7+ days at this time and it appears to work with NO side effects - the batch runs, files are sync'd, logs are generated as expected.

The first script ffs_sync.sh code snippet:

Code: Select all

        ... statements
# run the back-up
	export DISPLAY=:0
	/path/to/FreeFileSync/FreeFileSync  '/path/to/FreeFileSync/cf.ffs_batch'
        ... statements
The key is the
export DISPLAY=:0
statement.

I tried using gnome-terminal :

Code: Select all

        ... statements
# run the back-up
	export DISPLAY=:0
	gnome-terminal -x /path/to/FreeFileSync/FreeFileSync '/path/to/FreeFileSync/cf.ffs_batch'
        ...statements
It worked but a terminal flashed-up while the FFS batch was running - very distracting and annoying.

The crontab job is simple - run ffs_sync.sh (use first code snippet example) everyday at 3:15 AM:

Code: Select all

15 3 * * * /path/to/FreeFileSync/ffs_sync.sh
Adding script logging works as well:

Code: Select all

15 3 * * * /path/to/FreeFileSync/ffs_sync.sh >> /path/to/mylogs/ff_sync.log 2>&1 
GS can still be used when available - select "Default behaviour" rather than "X application"

This works on Devuan and Linux Mint 19 32/64 bit systems.

User avatar
Zenju
Site Admin
Posts: 4927
Joined: 9 Dec 2007

Post by Zenju • 04 Jun 2019, 14:04

Ideally, FFS would somehow offer a portable task scheduler (ramp up RTS?), but let's not hold our breath: Until then it probably makes sense to replace the gnome-schedule manual section by a short intro to "crontab" in the context of FFS showing the minimum steps needed, such as:

Code: Select all

EDITOR=gedit crontab -e
It seems we can get rid of the sh file:

Code: Select all

*/1 * * * * DISPLAY=:0 /path/to/FreeFileSync/FreeFileSync ${HOME}/Desktop/SyncJob.ffs_batch
or alternatively:

Code: Select all

*/1 * * * * export DISPLAY=:0; /path/to/FreeFileSync/FreeFileSync ${HOME}/Desktop/SyncJob.ffs_batch

tmountney
Posts: 5
Joined: 23 May 2019

Post by tmountney • 07 Jun 2019, 20:35

Over several days, I tested both:

Code: Select all

*/1 * * * * DISPLAY=:0 /path/to/FreeFileSync/FreeFileSync ${HOME}/Desktop/SyncJob.ffs_batch

Code: Select all

*/1 * * * * export DISPLAY=:0; /path/to/FreeFileSync/FreeFileSync ${HOME}/Desktop/SyncJob.ffs_batch
Neither executes the scheduled FFS batch - no log is generated, no files are sync'd.

The same FFS batch configuration, when run from the application, works as expected - a log is generated, files are sync'd

Using the same FFS batch configuration and executing it from a scheduled script that exports DISPLAY and then executes the FFS batch, executes as expected - a log is generated, files are sync'd.

It "seems" that using a scheduled script that exports DISPLAY and then executes the FFS batch is required.

I tested this on 3 distros - Linux Mint 19 32/64 bit and Devuan 2 64 bit - with the same results; it only works if I use a script...

User avatar
Zenju
Site Admin
Posts: 4927
Joined: 9 Dec 2007

Post by Zenju • 12 Jun 2019, 12:19

I don't see why the crontab syntax should require a sh file on one system but not on the other. I'd suggest checking what error information is available from crontab. E.g. it may have sent an email to the local account in /var/spool/mail/<username>

bgstack15
Posts: 54
Joined: 7 Jan 2018

Post by bgstack15 • 15 Jun 2019, 22:20

If your provided examples use the shell variable "${HOME}" specifically, the cron jobs will not be able to send the right variable. The variable $HOME is a bash built-in, which from man bash(1) is described:
HOME

The home directory of the current user; the default argument for the cd builtin command. The value of this variable is also used when performing tilde expansion.
Cron generally runs as root, and you can simply tell a cron job to run as a particular user. However, exact ways of doing that will vary, and your cron table doesn't look like the one I'm familiar with where you make the first value after the timing be equal to the username who will run the command.

And instead of explaining the nuances of cron here, I will tell you: You should change the environment-dependent variable $HOME to be a specific path name.

So:

Code: Select all

*/1 * * * * DISPLAY=:0 /path/to/FreeFileSync/FreeFileSync /home/tmountney/Desktop/SyncJob.ffs_batch