The idea of using crontab to schedule netcat commands on two machines was brought up in this question, but the respondents all rebuked the asker and pivoted to talking about scp
instead.
Assuming I am ok with the implications, how would I go about finding what went wrong with this setup? For testing purposes, I was synchronizing these two jobs at 13:45 local. Both computers are on the same local time zone.
Destination crontab:
45 13 * * * nc -l -p 1234 > /path/to/backup-$(date +%F).tar.bz2
Source crontab:
45 13 * * * /path/to/backup_script.sh
Source backup script:
sleep 5 # to ensure the destination is already listening
tar -cvpj --exclude-vcs /path/to/source/files | nc -N dest 1234
On their own (outside of crontab), the listen command and backup script work. It's my understanding that the destination will not stop listening until it receives EOF. However, it's the listening end that seems to not be listening when it should be. I can start it listening manually and the source's scheduled job will send the file, but I'm unable to get the destination to listen at a specified time.
%
character - see for example How can I executedate
inside of a cron tab job? – steeldriver Nov 26 '20 at 23:04bash myscript.sh
(even though it had shebang and was executable), and in doing so I no longer had to escape the%
. – kjekk Nov 27 '20 at 03:32