So I made a bash script to ssh onto lots of computers and play a sound all at once. I'm running into issues when trying to sync them though. My approach is:
Get current epoch on my computer,
Add a 20 second delay (to allow for transfer times) [target_epoch]
connect to & send .wav files to each computer in parallel.
Run a few lines of bash on each computer:
sync time with google,
get bot epoch
calc how long to sleep based off: target_epoch - bot_epoch
sleep and then play .wav file
Getting my computer epoch with:
current_epoch=$(date +%s.%N)
target_epoch=$(echo "$current_epoch + 20"|bc)
Code running on each remote computer:
sudo date -s '$(wget --method=HEAD -qSO- --max-redirect=0 google.com 2>&1 | sed -n 's/^ *Date: *//p')';\
bot_current_epoch=$(date +%s.%N);\
echo 'Current epoch: ' ${bot_current_epoch};\
echo 'Target epoch: ' ${target_epoch};\
amixer set 'Master' ${volume}% 1> /dev/null;\
echo 'Sleep until:${target_epoch} time now: ${bot_current_epoch}' ;\
echo 'Sleep for: '$(echo "$target_epoch - $bot_current_epoch"|bc);\
sleep $(echo "$target_epoch - $bot_current_epoch"|bc);\
aplay /tmp/${wavFile} 2> /dev/null;"
(oh, I'm saving that code as a string and then passing it via ssh to the remote computer)
the issue I have is that it's not setting the bot_current_epoch variable
originally I had bot_current_epoch use the same name as current_epoch and so it didn't update the current epoch time so all bots just waited for the 20-second delay and didn't actually sync up. When I changed the var to bot_current_epoch it failled and I noticed that bot_current_epoch=$(date +%s.%N);\ wasn't actually updating the var