Hello everybody,
I'm trying to schedule a sync job with Cron on my Ubuntu VM (24.04 LTS). I have read through zenju's updated manual (https://freefilesync.org/manual.php?topic=schedule-batch-jobs#linux , thank you zenju) but in my case, it's still not working.
Line in cron file:
0 9 * * 4 /opt/FreeFileSync/FreeFileSync "/home/sync-admin/Documents/NAS_sync.ffs_batch"
(when I'm testing it I'm changing start time of course, I'm not checknig this once a day :-P )
When I set it up like this, literally nothing happens. When I execute just this command in terminal /opt/FreeFileSync/FreeFileSync "/home/sync-admin/Documents/NAS_sync.ffs_batch" FFS icon appears in the taskbar and sync is running in the background.
I'm attaching printscreens showing cron file and permissions for FFS batch file.
I appreciate your help, I'm starting to rip my hair out. :-D
Thanks.
Yet another Cron problem
- Posts: 8
- Joined: 23 Dec 2024
- Attachments
-
- cron-problem2.png (70.59 KiB) Viewed 584 times
-
- cron-problem1.png (464.37 KiB) Viewed 584 times
- Site Admin
- Posts: 7279
- Joined: 9 Dec 2007
Most likely an error was written to stderr. I'd start with something like:
Let the command run every minute and see if there is anything logged to a file on your desktop:
cron by default tries to send an email when the command fails, which it assumes when it finds output to stderr or stdout. Assuming that you haven't set up system email, do this alternatively:journalctl | grep cron
Let the command run every minute and see if there is anything logged to a file on your desktop:
* * * * * /opt/FreeFileSync/FreeFileSync /home/sync-admin/Documents/NAS_sync.ffs_batch >> /home/sync-admin/Desktop/NAS_sync.txt 2>&1
- Posts: 8
- Joined: 23 Dec 2024
There wasn't much in that.
Dec 28 19:00:01 Ubuntu-NAS-sync CRON[15717]: pam_unix(cron:session): session opened for user sync-admin(uid=1000) by sync-admin(uid=0)
Dec 28 19:00:01 Ubuntu-NAS-sync CRON[15717]: pam_unix(cron:session): session closed for user sync-admin
But I have figured out in the end with the help of ChatGPT. I'm total Linux noob, so I might have set up something incorrectly when setting server up or missed some easy solution, but this is what I had to do for my specific setup and need.
Setup:
Ubuntu VM (24.04 LTS), running on Proxmox. It's pretty much headless, running only one FFS job once a week (syncing my two NASes). I wanted it to work without any user signed and unattended.
I think the main problem was that program is launching as GUI application, so display had to be specified in Cron, but having it system-wide set up (so it works without any user signed in) I needed to add cron job to /etc/crontab . And there I stumbled on another problem - root didn't have privileges for X... So I had to install xvfb and use that.
Steps (copied mostly from ChatGPT):
1. Ensure Required Dependencies Are Installed
Install Xvfb for running GUI-based applications in a headless environment:
sudo apt-get install xvfb
Verify FreeFileSync and its dependencies are installed correctly.
2. Prepare the Bash Script
Create a bash script (ffs_launcher.sh) that:
Starts a virtual display using Xvfb.
Sets the DISPLAY environment variable for the GUI application.
Runs the *.ffs_batch script via FreeFileSync.
Stops Xvfb after execution.
Example Script (/opt/scripts/ffs_launcher.sh):
!/bin/bash
# Start Xvfb on display :99
Xvfb :99 -screen 0 1024x768x24 &
XVFB_PID=$! # Capture Xvfb's process ID
# Set DISPLAY environment variable
export DISPLAY=:99
# Run the application
/opt/FreeFileSync/FreeFileSync /opt/scripts/NAS_sync.ffs_batch
# Stop Xvfb after the application finishes
kill $XVFB_PID
Make the script executable:
chmod +x /opt/scripts/ffs_launcher.sh
3. Test the Script
Run the script manually to ensure it works:
sudo /opt/scripts/ffs_launcher.sh
4. Add the Script to Cron
To run the script as root (even if no user is logged in), use the root user’s crontab or edit /etc/crontab:
Using sudo crontab -e:
0 9 * * 4 /opt/scripts/ffs_launcher.sh
Using /etc/crontab:
Edit the file:
sudo nano /etc/crontab
Add the line:
0 9 * * 4 root /opt/scripts/ffs_launcher.sh
Dec 28 19:00:01 Ubuntu-NAS-sync CRON[15717]: pam_unix(cron:session): session opened for user sync-admin(uid=1000) by sync-admin(uid=0)
Dec 28 19:00:01 Ubuntu-NAS-sync CRON[15717]: pam_unix(cron:session): session closed for user sync-admin
But I have figured out in the end with the help of ChatGPT. I'm total Linux noob, so I might have set up something incorrectly when setting server up or missed some easy solution, but this is what I had to do for my specific setup and need.
Setup:
Ubuntu VM (24.04 LTS), running on Proxmox. It's pretty much headless, running only one FFS job once a week (syncing my two NASes). I wanted it to work without any user signed and unattended.
I think the main problem was that program is launching as GUI application, so display had to be specified in Cron, but having it system-wide set up (so it works without any user signed in) I needed to add cron job to /etc/crontab . And there I stumbled on another problem - root didn't have privileges for X... So I had to install xvfb and use that.
Steps (copied mostly from ChatGPT):
1. Ensure Required Dependencies Are Installed
Install Xvfb for running GUI-based applications in a headless environment:
sudo apt-get install xvfb
Verify FreeFileSync and its dependencies are installed correctly.
2. Prepare the Bash Script
Create a bash script (ffs_launcher.sh) that:
Starts a virtual display using Xvfb.
Sets the DISPLAY environment variable for the GUI application.
Runs the *.ffs_batch script via FreeFileSync.
Stops Xvfb after execution.
Example Script (/opt/scripts/ffs_launcher.sh):
!/bin/bash
# Start Xvfb on display :99
Xvfb :99 -screen 0 1024x768x24 &
XVFB_PID=$! # Capture Xvfb's process ID
# Set DISPLAY environment variable
export DISPLAY=:99
# Run the application
/opt/FreeFileSync/FreeFileSync /opt/scripts/NAS_sync.ffs_batch
# Stop Xvfb after the application finishes
kill $XVFB_PID
Make the script executable:
chmod +x /opt/scripts/ffs_launcher.sh
3. Test the Script
Run the script manually to ensure it works:
sudo /opt/scripts/ffs_launcher.sh
4. Add the Script to Cron
To run the script as root (even if no user is logged in), use the root user’s crontab or edit /etc/crontab:
Using sudo crontab -e:
0 9 * * 4 /opt/scripts/ffs_launcher.sh
Using /etc/crontab:
Edit the file:
sudo nano /etc/crontab
Add the line:
0 9 * * 4 root /opt/scripts/ffs_launcher.sh