dir=${1:-"$HOME/Downloads/corr_age/20250225_test1"}

mkdir -p "$dir"

set -x


# Kill unpack_cmr.py processes
for dev in "m178" "m179" "m9"
do
   ssh ${dev} 'sudo kill $(pgrep -f unpack_cmr.py)'
   ssh ${dev} 'sudo killall nc'
done

# Copy the data
for dev in "m178" "m179" "m9"
do
   scp ${dev}:/tmp/*.csv ${dev}:/tmp/*.bin ${dir}/
done

# Delete the old data
for dev in "m178" "m179" "m9"
do
   ssh ${dev} sudo rm -f /tmp/*.csv /tmp/*.bin
done
