This page looks best with JavaScript enabled

Shell Ftp File and Email

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash

##### VAR #####
SH_DIR=/export/home/prdadm/fmsftp
PURPOSE="email_tittle_or_name"
IP=10.1.1.1
ftp_in=get_xxx.in
MAIL_LIST=xxx@aptg.com.tw,xxx2@aptg.com.tw
####################

cd $SH_DIR

##### make .in #####
echo user fmsftp fmsftp >$ftp_in
echo bin >>$ftp_in
echo prompt off >>$ftp_in
echo lcd /export/home/prdadm/fmsftp/ToSapData >>$ftp_in
echo cd /etl/DATA/DPQS/SAP >>$ftp_in
echo mget *PQS_OUT.csv >>$ftp_in
echo bye >>$ftp_in
####################

echo "***** ftp start *****" >ftp.log
echo time: $(date '+%Y/%m/%d %A %H:%M:%S') >>ftp.log
echo $PURPOSE >>ftp.log

echo "" >>ftp.log
ftp -vin $IP <$ftp_in >>ftp.log
echo "" >>ftp.log

if [ $? -ne 0 ]; then
    echo " folder is empty " >>ftp.log
fi

echo "***** ftp end *****" >>ftp.log
echo " " >>ftp.log
echo " " >>ftp.log

cat ftp.log >>ftp_total.log

##### send mail #####
mailx -s $PURPOSE $MAIL_LIST <ftp.log