issues with cronjob

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

Homer-S

Hello,

I read so many and tried even more but I am not able to run my batch jobs on my
Ubuntu 18.04 server by a crontab job.
Is there somewhere an working crontab command existing for sudo?

All attempts with a single command in crontab was without success. I ended up now in calling a bash script but this is also not working ...

Any help is highly appreciated


This is my script:
#!/bin/sh

export DISPLAY=$(source /home/homer/skripte/ffs-display-export.sh)
echo "Disp1"
echo $DISPLAY
DISPLAY=$(source /home/homer/skripte/ffs-display-export.sh)
echo "Disp2"
echo $DISPLAY
#sudo /home/homer/Software/FreeFileSync/FreeFileSync '/home/homer/Documents/Daten2BackupDaten.ffs_batch' 2>&1

#/home/homer/Software/FreeFileSync/FreeFileSync '/home/homer/Documents/Daten2BackupDaten.ffs_batch' 2>&1
/usr/bin/env DISPLAY=$DISPLAY /home/homer/Software/FreeFileSync/FreeFileSync '/home/homer/Documents/Daten2BackupDaten.ffs_batch' 2>&1
Posts: 309
Joined: 7 Jan 2018

bgstack15

FreeFileSync, as a graphical application, needs a valid $DISPLAY variable. I can see that you are trying to populate that variable, but I don't understand the sub-shell invocation and separate script.

An entry in "crontab -e" under root or another user would probably resemble:
0 4 * * *  /home/homer/skripte/ffs-cron.sh 1>/dev/null 2>&1
Where 1> and 2> redirect the output of cron to /dev/null. A well-behaved script will perform its own logging and alerting and not depend on cron to do those tasks. Cron by default will try to send an email to root, which isn't really how most admins or users want to see the output of cron.
And the ffs-cron.sh script would probably look like:
#!/bin/sh
export DISPLAY=:0
/home/homer/Software/FreeFileSync/FreeFileSync /home/homer/Documents/Daten2BackupDaten.ffs_batch
The :0 value is the default value for most display managers. The first login session is most likely going to be :0. You can confirm that by opening a terminal emulator in your main graphical session and type:
echo $DISPLAY
Whatever that value is, use that in your ffs-cron.sh script above.

Remote sessions (vnc, x2go, rdp, etc.) tend to start at :10 but all of these values are configurable. And sometimes you even have a decimal value, such as :10.0. I forget the reasons behind the decimal.

Additionally, the DISPLAY value points to a running X server. It is possible that if your computer is only at the login screen (display manager) and no one is logged in on any graphical virtual terminal, then the :0 DISPLAY value is owned by root and your user may fail to start up FreeFileSync.
Posts: 8
Joined: 21 Nov 2019

Homer-S

Sorry for my late reply. I found finally some time to change it.

This is the log entry:
No protocol specified
11:00:01: Error: Unable to initialize GTK+, is DISPLAY set properly?

for this cron job
0 11 * * * /bin/bash /home/homer/skripte/ffs_daten_backup.sh >> /home/homer/cronlogsudo.log 2>&1

my echo $DISPLAY tells me 10.0

this is the script entry:
export DISPLAY=:10.0

Can it be that this issue is happening?
Additionally, the DISPLAY value points to a running X server. It is possible that if your computer is only at the login screen (display manager) and no one is logged in on any graphical virtual terminal, then the :0 DISPLAY value is owned by root and your user may fail to start up FreeFileSync.

But how can I fix this?

Thanks