FreeFileSync in a cronjob but sudo issues

Get help for specific problems
Posts: 8
Joined: 21 Nov 2019

Homer-S

I am trying now for a week to get my Freefilesync batch jobs running headless. I read a lot and this lead me to this set up:

sudoers.d/ffs
homers ALL = NOPASSWD: /home/homers/Software/FreeFileSync/FreeFileSync
this is to avoid issues coming from sudo crontab commands. (read in a differ forums)

in my crontab I am having this line now:
0 14 * * *  sudo env DISPLAY=:10.0 /home/homers/Software/FreeFileSync/FreeFileSync /home/homers/Documents/data2databkp.ffs_batch 2>&1 | /home/homers/scripts/timestamp.sh >> /home/homers/ffs.log
If I am using :0.0 I am receiving a DISPLAY set properly error. And now I am having a different issue with this:
sudo: no tty present and no askpass program specified
Any help is highly appreciated.

BTW all is on a ubuntu 18.0.4 server
Posts: 309
Joined: 7 Jan 2018

bgstack15

Sudo differentiates between running a command, and running a command with parameters.
You could set your sudoers this way:
homers ALL = NOPASSWD: env DISPLAY=:10.0 /home/homers/Software/FreeFileSync/FreeFileSync *
The asterisk at the end means you can use any additional parameters on the exact command "env DISPLAY=:10.0 /home/homers/Software/FreeFileSync/FreeFileSync" such as the file you want to run.

It is also pretty much going to be required that you have a running VNC session on :10.0 in that case. If you have a display manager running (gdm, lightdm, sddm, or others) you should have DISPLAY=:0 available to the root user.
Posts: 8
Joined: 21 Nov 2019

Homer-S

Thanks for your answer and help.

When adding " env DISPLAY=:10.0 " this to my sudoer config file, visudo is giving a syntax error.

May I ask what exactly you mean with this:
"
It is also pretty much going to be required that you have a running VNC session on :10.0 in that case. If you have a display manager running (gdm, lightdm, sddm, or others) you should have DISPLAY=:0 available to the root user."

Should I just use the env DISPLAY=:0.0 instead of the 10?

Big Thanks
Posts: 309
Joined: 7 Jan 2018

bgstack15

If you need to set exact variables for a cron job, it is probably best to make a separate script that runs FreeFileSync with the variables.
So, a script named /home/homers/bin/run-my-backup.sh
#!/bin/sh
export DISPLAY=:10.0
/home/homers/Software/FreeFileSync/FreeFileSync /home/homers/Documents/data2databkp.ffs_batch 2>&1 | /home/homers/scripts/timestamp.sh >> /home/homers/ffs.log
And then your cron job will look like:
0 14 * * *  /usr/bin/sudo /home/homers/bin/run-my-backup.sh 1>/dev/null 2>&1
Cron does not always have the $PATH that you expect, so fully qualify the path name of sudo.

And the sudoers entry:
homers ALL = (ALL) NOPASSWD: /home/homers/bin/run-my-backup.sh
And of course you need to make sure you chmod u+x /home/homers/bin/run-my-backup.sh
Posts: 1
Joined: 24 Nov 2019

unknownterritory

I had success using the following syntax:
* * * * *       /usr/bin/FreeFileSync/FreeFileSync '/path/to/sync-job.ffs_batch' --display=:0.0 2>&1
It seems unlikely that you can use 10 as the display sequence number as you probably don't have 10 displays connected to your computer.

HTH!

P.S.: I would post links to external pages with more information but, being new in this forum, it just barked at me accusing me of spamming.