#!/bin/bash
ALL_FILE=$0
EXEC=${ALL_FILE##*/}
##########################----------------MODEIFY BEGIN-----------#############################
#Need to modify the native path
SRC_PATH=
SRC_BACK=
SRC_LOG=
#Need to check the tmp path
DEST_TMP=
DEST_PATH=
#FTP host IP,port,account and password, need to be modified
HOST=
POST=21
USER=
PASSWD=
##########################----------------MODEIFY END ------------#############################
SRC_LOGfile=xxxx.SRC_LOG
function PUT_FILE()
{
ftp -in <<!
open $1 $2
use $3 $4
lcd $5
cd $6
put $7
mkdir ${DEST_PATH}
rename $7 ${DEST_PATH}/$7
bye
!
}
function CHECKDIR()
{
if [ ! -e $1 ]; then
echo "Path $1 not exist, mkdir" >> ${SRC_LOG}/${SRC_LOGfile}
mkdir -p $1
fi
}
function SIG_LIST_FTP()
{
find ./ -name "xxx*.*" | while read filename
do
echo "sub_dir: ${DEST_TMP} ${DEST_PATH} ${filename##*/}" >> ${SRC_LOG}/${SRC_LOGfile}
PUT_FILE ${HOST} ${POST} ${USER} ${PASSWD} ${SRC_PATH} ${DEST_TMP} ${filename##*/}
mv -f ${filename##*/} ${SRC_BACK}
echo `date` ":file ${filename##*/} put to HOST:${HOST} !!!" >> ${SRC_LOG}/${SRC_LOGfile}
done
}
ps -ef | grep ${EXEC} | grep -v grep| wc -l| grep -v vi|grep -v cat| read record
echo ${record}
if [[ ${record} -gt 1 ]]
then
echo ${EXEC} is exist!,${record}
exit
fi
CHECKDIR ${SRC_BACK}
CHECKDIR ${SRC_LOG}
cd ${SRC_PATH}
while true
do
SIG_LIST_FTP
ls -1 -t xxx.* | wc -l| while read fno
do
if [[ ${fno} -lt 1 ]]
then
# echo "no such file to FTP,sleep 60 s" >> ${SRC_LOG}/${SRC_LOGfile}
sleep 60
else
echo "The current remaining waiting for ${fno} file transfer..." >> ${SRC_LOG}/${SRC_LOGfile}
fi
done
done
一个ftp上传文件的模板,要说的很少,找着填就可以了,这里说明一下,用临时目录的原因在于ftp的过程中是会产生文件的,但文件可能不完整,最好将整个文件都传过来了,再用mv 指令移动到目标主机目录