Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  0] [ 0]  / answers: 1 / hits: 521  / 2 Years ago, fri, october 28, 2022, 6:46:49

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.


More From » scripts

 Answers
6

crontab commands (man -a crontab) are NOT bash. Redirection, and command substitution are not available in crontab commands.


Wrap your desired command in a bash script, beginning with #!/bin/bash, and invoke the script from the crontab entry.


[#2318] Saturday, October 29, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
anxietunnel

Total Points: 66
Total Questions: 120
Total Answers: 115

Location: Norway
Member since Sat, Mar 4, 2023
1 Year ago
;