Tip - alternative for gnome-schedule on Linux

Get help for specific problems
Posts: 6
Joined: 23 May 2019

tmountney

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:
        ... 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 :
        ... 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:
15 3 * * * /path/to/FreeFileSync/ffs_sync.sh
Adding script logging works as well:
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
Site Admin
Posts: 7048
Joined: 9 Dec 2007

Zenju

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:
EDITOR=gedit crontab -e
It seems we can get rid of the sh file:
*/1 * * * * DISPLAY=:0 /path/to/FreeFileSync/FreeFileSync ${HOME}/Desktop/SyncJob.ffs_batch
or alternatively:
*/1 * * * * export DISPLAY=:0; /path/to/FreeFileSync/FreeFileSync ${HOME}/Desktop/SyncJob.ffs_batch
Posts: 6
Joined: 23 May 2019

tmountney

Over several days, I tested both:
*/1 * * * * DISPLAY=:0 /path/to/FreeFileSync/FreeFileSync ${HOME}/Desktop/SyncJob.ffs_batch
*/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
Site Admin
Posts: 7048
Joined: 9 Dec 2007

Zenju

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>
Posts: 306
Joined: 7 Jan 2018

bgstack15

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:
*/1 * * * * DISPLAY=:0 /path/to/FreeFileSync/FreeFileSync /home/tmountney/Desktop/SyncJob.ffs_batch
Posts: 6
Joined: 23 May 2019

tmountney

Retested to confirm direct batch scheduling options...

Started fresh:

- Deleted all FFS related crontab jobs
- Using FFS, deleted the GUI and batch configs: Main.ffs_gui, Main.ffs_batch
- Rebooted system
- Configured/saved new GUI and batch configs: Main.ffs_gui, Main.ffs_batch
- Using FFS app, tested/confirmed both GUI and batch configs executed as expected - no errors, source/destination sync'd, logs created

Schedule Test 1
Created new USER crontab job:
*/1 * * * * DISPLAY=:0 /path/to/FreeFileSync/FreeFileSync /path/to/Main.ffs_batch

- Added new-file-1 to source
- Confirmed that cron job executed - no errors, source/destination sync'd
- Checked syslog - no CRON errors for FFS
- Checked FFS batch status in log-file - no errors, new-file-1 sync'd to destination

Schedule Test 2
Created new USER crontab job:
 */1 * * * * export DISPLAY=:0; /path/to/FreeFileSync/FreeFileSync /path/to/Main.ffs_batch
 
- ]Added new-file-2 to source
- Confirmed that cron job executed - no errors, source/destination sync'd
- Checked syslog - no errors
- Checked FFS batch status in log-file - no errors, new-file-2 sync'd to destination

I tested this scenario on 3 systems/distros - Mint 19 32 bit and 64 bit, and Devuan 2 64 bit.

ALL executed successfully - no errors, source/destination sync'd, logs generated on the 3 systems.

Additionally tested both scenarios using ${HOME} as path, on all 3 systems , e.g.:
*/1 * * * * DISPLAY=:0 ${HOME}/FreeFileSync/FreeFileSync ${HOME}/Main.ffs_batch

*/1 * * * * export DISPLAY=:0; ${HOME}/FreeFileSync/FreeFileSync ${HOME}/Main.ffs_batch
ALL executed successfully - no errors, source/destination sync'd, logs generated on the 3 systems.

I don't know why it didn't work the first time I tested - I followed
the same steps listed above. I allowed the cron job to run for several days - there was not one successful sync.

I probably mis-defined a property, path, or didn't punctuate (use of ';'), correctly... DOH...

My apology to all for any confusion this may have caused...

SO... this confirms that whether scheduling the FFS batch directly, or thru a
script, both execute successfully.
Posts: 6
Joined: 22 Feb 2019

Menel

Had a lot of issues with all of this, no specific errors, but not running. Then success! For future googlers:

Runs every 6 hours.
0 */6 * * * env DISPLAY=:0 /opt/FreeFileSync/FreeFileSync /home/plex/syncSFTP.ffs_batch
per https://help.ubuntu.com/community/CronHowto#GUI_Applications
Posts: 20
Joined: 21 Sep 2019

Gabe

Hi guys,

Just wanted to chime in. I landed here after realizing that gnome-schedule is not an (easy) option on Ubuntu now, so I wanted to try and use crontab instead. I admit this is the first time I try to set up a cron job.

Anyhow, I first fiddled with crontab to make sure I understood how it works, and I think I got the basics down.
But for the life of me I cannot get my ffs_batch job to run.
It works perfectly if I run it directly from the terminal. I get the logs and everything. But with cron, I am stuck with just a
(CRON) info (No MTA installed, discarding output)
when monitoring the cron status via systemctl

This is not the end of the world, I can also ask around here at work for help, but I thought I would flag that it ain't working for me.
Posts: 6
Joined: 22 Feb 2019

Menel

Hi guys,

Just wanted to chime in. I landed here after realizing that gnome-schedule is not an (easy) option on Ubuntu now, so I wanted to try and use crontab instead. I admit this is the first time I try to set up a cron job.

Anyhow, I first fiddled with crontab to make sure I understood how it works, and I think I got the basics down.
But for the life of me I cannot get my ffs_batch job to run.
It works perfectly if I run it directly from the terminal. I get the logs and everything. But with cron, I am stuck with just a
(CRON) info (No MTA installed, discarding output)
when monitoring the cron status via systemctl

This is not the end of the world, I can also ask around here at work for help, but I thought I would flag that it ain't working for me. Gabe, 22 Jul 2021, 11:14
You need to share more with us, your actual crontab file, syntax matters.

This:
grep CRON /var/log/syslog
Might show what cron is executing, and can identify discrepancy.

Also, MTA is mail t… a… something. You need a mail handler installed such as postfix, mutt, etc in order to capture the messages cron is trying to send you,
Posts: 20
Joined: 21 Sep 2019

Gabe

Never mind, I figured it out. My display ID is :1, not :0.

The code below seems to do the trick (and solves the missing MTA problem by creating a log file for the output).
* * * * * DISPLAY=:1 /usr/local/bin/FreeFileSync /home/user/shell_settings.ffs_batch >> /home/user/cron.log 2>&1
I still get the following error messages, though:
Gtk-Message: 15:31:58.987: Failed to load module "appmenu-gtk-module"
Gtk-Message: 15:31:58.994: Failed to load module "canberra-gtk-module"
The first error only shows up if I launch FFS from the command line, while the second one is also returned by CRON. But I assume this is off topic.

--------------------------------------

UPDATE

I think I was a bit too quick claiming victory. I have now changed the cron job to start at boot, by changing the beginning of the string to
@reboot DISPLAY=:1  [...]
And I am back to error messages:
16:39:08: Error: Unable to initialize GTK+, is DISPLAY set properly?
The above was the error message that pointed me in the right direction earlier today, and made me switch from "DISPLAY=:0" to "=:1". But now I don't know what to do. I assume it has something to do with how the DISPLAY value is initialized at boot. I tried all the following options, none seems to work:
@reboot DISPLAY=:1 /usr/local/bin/FreeFileSync /home/user/shell_settings.ffs_batch >> /home/gabe/cron.log 2>&1
@reboot env DISPLAY=:1 /usr/local/bin/FreeFileSync /home/user/shell_settings.ffs_batch >> /home/gabe/cron.log 2>&1
@reboot export DISPLAY=:1; /usr/local/bin/FreeFileSync /home/user/shell_settings.ffs_batch >> /home/gabe/cron.log 2>&1
@reboot DISPLAY=:0 /usr/local/bin/FreeFileSync /home/user/shell_settings.ffs_batch >> /home/gabe/cron.log 2>&1
@reboot env DISPLAY=:0 /usr/local/bin/FreeFileSync /home/user/shell_settings.ffs_batch >> /home/gabe/cron.log 2>&1
@reboot export DISPLAY=:0; /usr/local/bin/FreeFileSync /home/user/shell_settings.ffs_batch >> /home/gabe/cron.log 2>&1