We have something similar. We use LFTP so we can use user/password or
user/certificate, but same mechanism.
Here's my script:
#############################################
#!/usr/bin/bash
###CONSTANTS##########
retries=5
user=USUSND
password=PWDUSUSND
ipadd=MYSERVERIPADDR
predir=/OUTBOX
postdir=/OUTBOX_DONE/
remotedir=IN
dataarea=ESSELWARE/LFTP01
workdir=/home/ESSELWARE
mailaccount='useralert@xxxxxxxxxxxxxx:Passw0rd'
mailfrom='useralert@xxxxxxxxxxxxxx'
receptor='groupinterface@xxxxxxxxxxxxxx'
mailserver='smtp://mailserver.com:587'
#######################
# NOTAS
#######################
# alertsmail.txt is mail header:
# .......................................
#From: "Alerts" <useralerts@xxxxxxxxxxxxxx>
#To: "Interfaces Group" <groupinterface@xxxxxxxxxxxxxx>
#Subject: Alert - Error on File Transfer
#
#Error when transfering these files:
# .......................................
#######################
# Must create the DATA AREA as in dataarea
# DEC type. Suggestion: 8.0
#######################
system "CHGDTAARA $dataarea VALUE(0)"
for i in {1..$5}
do
retcode=0
lftp -C -c "open -u $user,$password s
ftp://$ipadd;lcd
$predir;cd $remotedir;mput *"
retcode=$?
if [ $retcode -eq 0 ]
then
## Exit code 0 means no errors found. Exiting loop ##
i=$retries
break
else
## Wait 10 seconds before retry ##
sleep 10
fi
done
## Check for errors ###
if [ $retcode -gt 0 ]
then
## Email alert when error found ##
cp $workdir/alertsmail.txt $workdir/alertsmail2.txt
ls -la $predir >> $workdir/alertsmdtk2.txt
echo "Código de salida : $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)"
#############################################
Good luck
Note: This is from my post on LinkedIn (Spanish)
https://www.linkedin.com/pulse/ibm-i-enviando-archivos-por-internet-reintentos-diego-kesselman/
El 9/7/18 a las 17:06, Jerry Draper escribió:
Let's say you have a CL pgm that does a CALL QP2BATCH(xx.sh <parms>)
where control goes over to the *ix side of the world.
Let's say that the xx.sh script runs and sFTP, python, or perl script.
What happens if one of these err out. How would the CL calling
process know?
We had one case where an sFTP script was erring out because the server
was displaying a connection msg. Once we piped std err to a file all
completed normally.
Thanks,
Jerry
As an Amazon Associate we earn from qualifying purchases.