-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathisftpretry.sh
54 lines (47 loc) · 1.52 KB
/
isftpretry.sh
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
43
44
45
46
47
48
49
50
51
52
53
54
###CONSTANTS##########
retries=5
user=USRSND
password=PWDUSRSND
ipadd=MYSERVERIPADDR
predir=/SENDING
postdir=/SENDING_DONE/
remotedir=IN
dataarea=ESSELWARE/LFTP01
workdir=/home/ESSELWARE
mailaccount='[email protected]:Passw0rd'
mailfrom='[email protected]'
receptor='[email protected]'
mailserver='smtp://mailserver.com:587'
files='*'
#######################
# Need to create DATA AREA $dataarea
# as DEC 8.0
#######################
#Initializing Data Area value
system "CHGDTAARA $dataarea VALUE(0)"
for i in {1..$retries}
do
retcode=0
lftp -C -c "open -u $user,$password sftp://$ipadd;lcd $predir;cd $remotedir;mput $files"
retcode=$?
if [ $retcode -eq 0 ]
then
## Exiting loop when exit code equals 0 (no error) ##
i=$retries
break
else
## Wait 10 seconds when return code differs from 0 (with error) before next attempt ##
sleep 10
fi
done
## Check for errors ###
if [ $retcode -gt 0 ]
then
## Send email when return code differs from 0 (with error) ##
cp $workdir/alertsmail.txt $workdir/alertsmail2.txt
ls -la $predir >> $workdir/alertsmail2.txt
echo "Exit Code : $retcode ">>$workdir/alertsmail2.txt
curl --url $mailserver --ssl-reqd --mail-from $mailfrom --mail-rcp $receptor --user $mailaccount --insecure --upload-file $workdir/alertsmail2.txt
mv $predir/* $postdir
fi
system "CHGDTAARA $dataarea VALUE($retcode)"