Start @reboot crontab script in a new tmux/byobu session and be able to connect to it

I have a crontab entry that starts a backup job script after reboot:

@reboot (sleep 120 && bash /srv/recvuser/ 2>&1 | /usr/bin/mail -s "SuperServer ZFS Backup"

This works. However, the script can take a while (1-2 days). In this time, I want to be able to connect to the session and see the progress. I thought byobu/tmux would be a good idea:

@reboot (sleep 120 && byobu new-session -d -s "backup-job" "bash /home/recvuser/ 2>&1 | /usr/bin/mail -s 'SuperServer ZFS Backup'"

However, this does not seem to work. byobu list-session is empty.

Any idea how I can accomplish my goal to see the progress, while still keeping my postfix mail at the end?

Asked By: Alex


No answer so far. Adding here me solution: Sometimes, you don’t notice the easy solution!

I realized I don’t need byobu or tmux for this.

What I did is writing logs to a local file and mailing the result. This allows me to 1) receive all logs via email, once finished and 2) tail the logfile in case I want to see the current progress
@reboot  /bin/bash -c '(sleep 120 && bash /home/recvuser/ 2>&1 | tee /home/recvuser/logfile.log' | /usr/bin/mail -s "SuperServer ZFS Backup"

Then simply see the current status with:

tail -f logfile.log
Starting pull snapshots at 2024-03-12
Pulling: rpool/data -> tank/proxmox/rpool/data
NEWEST SNAPSHOT: autosnap_2024-03-12_00:00:41_daily
Sending incremental rpool/data@autosnap_2024-03-01_00:00:41_monthly ... autosnap_2024-03-12_00:00:41_daily (~ 4 KB):
Pulling: rpool/ROOT/pve-1 -> tank/proxmox/rpool/ROOT/pve-1
NEWEST SNAPSHOT: autosnap_2024-03-12_00:00:41_daily
Sending incremental rpool/ROOT/pve-1@autosnap_2024-03-01_00:00:41_monthly ... autosnap_2024-03-12_00:00:41_daily (~ 379.0 MB):
Pulling: tank_hdd/data -> tank/hdd/data
NEWEST SNAPSHOT: autosnap_2024-03-12_04:00:40_hourly
Sending incremental tank_hdd/data@autosnap_2024-03-02_00:00:41_daily ... autosnap_2024-03-12_04:00:40_hourly (~ 5.6 GB):
Answered By: Alex
Categories: Answers Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.