Here is an example of a loop that will compress and send how ever many files are found to another server.
first_list=’/ [path] / [to] / [files] / *.*’
for raw in $first_list
gzip -9 $raw
second_list=’/ [path] / [to] / [files] / *.gz’
for gz in $second_list
scp $gz [user] @ [destination hostname/ip]:/ [path] / [to] / [destination] / [directory]
if [ $? != 0 ]; then
echo `eval date +%x` `eval date +%X` ” – transfer failed: “$gz >> / [path] / [to] / [files] / results / fail.txt
echo “transfer complete: “$gz >> / [path] / [to] / [files] / results / success.txt
# uncomment below to remove file once sent
# rm -f $gz
This is a great site to use (in addition to this one) for some more bash scripting help.