My simple bash script to fetch images of a Raspberry Pi that are older than one minute:
#!/bin/bash
time=`date +"%FT%H_%M_%S"`
imagedir="/root/pilapse/images/"
files=`ssh pi find /home/pi/weatherPi-images/ -type f -mmin +1`
echo -e "\033[1;32mFetching images from Raspberry Pi\033[1;00m"
for currFile in "${files[@]}"; do
echo -e "rsync -a --remove-source-files --info=progress2 -e ssh pi:$currFile $imagedir\n"
done
echo -e "rsync [...]"
is here just a placeholder for debugging.
Expected output:
rsync -a --remove-source-files --info=progress2 -e ssh pi:/home/pi/weatherPi-images/2016-02-01T13_22_20.jpg /root/pilapse/images/
rsync -a --remove-source-files --info=progress2 -e ssh pi:/home/pi/weatherPi-images/2016-02-01T13_14_07.jpg /root/pilapse/images/
Actual output:
rsync -a --remove-source-files --info=progress2 -e ssh
horizon:/home/pi/weatherPi-images/2016-02-01T13_22_20.jpg
/home/pi/weatherPi-images/2016-02-01T13_14_07.jpg
/home/pi/weatherPi-images/2016-02-01T13_18_45.jpg
/home/pi/weatherPi-images/2016-02-01T13_13_37.jpg /root/pilapse/images/
Somehow bash seems to expand the array here, but why? In my understanding in the foreach-loop above currFile
contains only one path.