Вкратце: Мне нужно загрузить данные с устройства на базе Linux, проверить целостность данных и удалить исходные файлы (нельзя использовать rsync).
Подробности: У меня есть гидрофон, установленный на дне океана как часть океанской обсерватории. Их гидрофон запускает [очень] легкий RHEL-подобный дистрибутив Linux с завода. Гидрофон генерирует новый файл .wav каждые 5 минут и сохраняет его на SD-карте. Внутреннее хранилище мало, поэтому мы хотели бы получить данные с помощью cronjob / скрипта, запущенного на «поисковой машине» на берегу, полностью проверить переданные файлы, а затем удалить исходные файлы с гидрофона. Моей первой мыслью было использовать rsync, но исходный код не разрешает подключения rsync (см. Сложности ниже).
Осложнения:
Имена файлов имеют следующий формат: SBW_yyyymmdd_HHMMSS.wav
Заранее благодарим вас за помощь и ответы, и, пожалуйста, дайте мне знать, смогу ли я улучшить ясность / детализацию вопроса.
ОБНОВИТЬ: После некоторых советов в комментариях ниже и грубых попыток я пришел к этому (я немного обобщил результат). Скрипт запускается каждые 5 минут как задание cron на нашем сервере поиска. Это ужасно медленно и неэффективно. Любой ввод будет полезен!
#!/bin/bash
## Define Variables
remUser="<user>" # Hydrophone SSH Username
remHost="<remote-host>" # Hydrophone hostname
sshCon="$remUser@$remHost"
## Remove previous md5 and get current MD5 Sums from remote-host
echo "Getting remoteWAV.md5 info"
rm -f remoteWAV.md5
ssh $sshCon 'cd ~/Data; md5sum *.wav' > remoteWAV.md5
## Check exit status and exit if bad connection
if [ $? -gt 0 ]; then echo "Connection failed, aborting"; exit 1; fi
## Wait One minute for any changes to remote files
### This is to allow any in-progress files the chance
### to change their md5sum from the ones gathered earlier
echo "pausing 60 sec..."
sleep 60
echo "resuming..."
## Download the files
echo "Getting files from remote host"
scp $sshCon:~/Data/*.wav /path/to/local-data-files/
if [ $? -gt 0 ]; then echo "Connection failed, aborting"; exit 1; fi
## Check the md5 sums
## - First delete the old localWAV.md5 file
## - Then we need to add the local directory to the filenames
## - Now we can finally check the remote vs local checksums
echo "Checking local files against remoteWAV.md5 sums"
rm -f localWAV.md5
sed -i 's|SBW|/path/to/local-data-files/SBW|g' remoteWAV.md5
md5sum -c < remoteWAV.md5 > localWAV.md5
## Display checksum results
echo "Local MD5 results:"
echo "=================="
cat localWAV.md5
## Remove files that failed md5sum check from local storage
## (This is so users don't download bad data)
cat localWAV.md5 | grep -v "OK" | cut -d ":" -f 1 | xargs -I {} rm -fv {}
## Find list of files that were downloaded successfully
## - First remove the old goodfiles.tmp list
## - Create a new listing of files that passed the md5sum check
## but remove the last (most recent) file from the list in case
## it is still being written on the remote host (second safety check)
## - Remove the local directory from the filenames
## - Copy the list of good files to the remote host
## - Issue the delete command on the remote host
rm -f goodfilesWAV.tmp
head -n -1 localWAV.md5 | grep "OK" | cut -d ":" -f 1 > goodfilesWAV.tmp
sed -i 's|/path/to/local-data-files/||g' goodfilesWAV.tmp
echo "Sending deletion list to remote host"
scp ./goodfilesWAV.tmp $sshCon:~/Data/
echo "Removing files from remote host"
ssh $sshCon 'cd ~/Data; xargs rm -fv < goodfilesWAV.tmp; rm goodfilesWAV.tmp'
echo "Complete."