#!/bin/sh if [ `id -un` != "domaine" ]; then echo "Not proper user, will not run, sorry." echo "Execute 'sudomaine' first." exit 1 fi # need to turn on nullglob so that 'n=($)' will return nothing # if there are no files in the directory, instead of returning an array # with '*' as the only element. shopt -s -q nullglob pushd /DI_Sales/ftp rm -f 111/* rm -f 107/* ftp -p -n -i 67.59.147.151 < get_data.ftp >> ftp-out.txt pushd 111 x=(*); n=${#x[@]} if [ $n != 0 ]; then pushd /DI_Sales/incoming/111 rm yesterday.zip zip yesterday.zip *.txt rm *.txt cp /DI_Sales/ftp/111/* ./ echo `date` moved $n files to /DI_Sales/ftp/111/ >> /DI_Sales/ftp/move-log.txt popd else echo `date` no files to move for 111. >> /DI_Sales/ftp/move-log.txt fi popd pushd 107 x=(*); n=${#x[@]} if [ $n != 0 ]; then pushd /DI_Sales/incoming/107 rm yesterday.zip zip yesterday.zip *.txt rm *.txt cp /DI_Sales/ftp/107/* ./ echo `date` moved $n files to /DI_Sales/ftp/107/ >> /DI_Sales/ftp/move-log.txt popd else echo `date` no files to move for 107. >> /DI_Sales/ftp/move-log.txt fi popd popd