我想自动执行以下操作的批处理作业:
这就是我所做的:
Pattern
很困惑,不知道该怎么做,有人可以帮帮我吗?
答案 0 :(得分:0)
我这样做了,它运作良好:
#!/bin/bash
host='ftp.xxxx.com'
USER='xxxx'
PASSWD='xxxx'
FTPFile1="/TEST/file.txt"
FTPFile2="/TEST/file.trt"
#search file.txt et file.trt on the ftp server
ftp -n -v $host << EOT
ascii
user $USER $PASSWD
prompt
mls $FTPFile1 $FTPFile2 test.txt
quit
EOT
# # ----------------------------------------------------------------------------------------------------------------------#
# # test if file.txt et file.trt are present => send mail
# # ----------------------------------------------------------------------------------------------------------------------#
if grep -inr '/TEST/file.txt' test.txt && grep -inr '/TEST/file.trt' test.txt
then
echo "" | mail -s "aaaaa] Error, aaaaa." mail@mail.fr -c mail@mail.fr
elif grep -inr '/TEST/file.txt' test.txt
then
echo "The File file.trt does not Exist (no loading at the moment), rename file.txt to file.trt and start loading";
# ----------------------------------------------------------------------------------------------------------------------#
# rename file.txt
# ----------------------------------------------------------------------------------------------------------------------#
ftp -n -v $host<< EOT
user $USER $PASSWD
get $FTPFile1 file.txt
rename $FTPFile1 $FTPFile2
quit
EOT
else
echo " file.txt (file not yet ready). No action to do."
fi
# ------------------------------------#
ftp -n -v $host << EOT
user $USER $PASSWD
get $FTPFile1 file.txt
quit
EOT
TRT_DATE=`cat file.txt | grep -Po "[0-9]{8}"`
# run my_script.sh
./my_script.sh -d $TRT_DATE
#delete file.txt et test.txt
rm -f file.txt test.txt
# delete file.trt
ftp -n -v $host << EOT
user $USER $PASSWD
delete $FTPFile2
quit
EOT
exit 0