シェルでLFTPでファイルを取得する必要があったので。
#!/bin/sh
echo "処理開始" >> result.log
# LFTP接続
lftp -f command.txt >> ftp.log
# ftp.logに先頭から始まる「abc*」がない場合
if ! grep "^abc*" ftp.log > /dev/null 2>&1; then
# ftp.logの内容をresult.logに移し、ftp.logを初期化し、処理正常
cat ftp.log >> result.log
echo "処理終了(ファイルなし)" >> result.log
cp /dev/null ftp.log
exit 0
# ftp.logに先頭から始まる「abc*」がある場合
else
# ftp.logの内の先頭から始まる「abc*」をgrepする
for X in `grep "^abc*" ftp.log`
do
# ファイル名(grep結果)が取得できている場合(-eが存在確認)
if [ ! -e $X ]; then
# ftp.logの内容をresult.logに移し、ftp.logを初期化し、処理異常
cat ftp.log >> result.log
echo "ファイル転送エラー" >> result.log
cp /dev/null ftp.log
exit 1
fi
done
fi
# ftp.logの内容を初期化し、処理正常
echo "処理終了" >> result.log
cp /dev/null ftp.log
exit 0;
command.txtの内容
open IP
user ユーザ名 パスワード
cd /test
cls abc*.txt
mget abc*.txt
ftp.logは処理が終了すると0バイトに初期化するが、
処理中は下記状態となる。
【正常の場合(取得ファイルあり)】
abc1.txt
abc2.txt
【正常の場合(取得ファイルなし)】
ファイル取得エラー
【異常の場合】
abc1.txt
abc2.tx
ファイル転送エラー