Useful ftp script for some daily transfers.
Useful ftp script to transfer files from SAP server daily to another file server.
In my case I transferred daily audit logs from SAP ERP server to another file server.
1)Create a .netrc file under root user $HOME directory / . There is sample netrc file under /usr/samples/tcpip/ .
Register file server IP and login credentials:
machine <IP> login <username> password <password>
Its rights should be 600 (rw- — —) . Otherwise we get an error like:
chmod 600 .netrc
Then we can immediatley login to file server (which we’ll transfer our audit files to).
2)Here is the little script /tmp/FtpDailyAudit.sh :
#!/bin/ksh
#Calculating YESTERDAY variable value
YESTERDAY=`TZ=bb24 date +%Y%m%d`
YESTERDAYS_AUDIT_FILE=”audit_$YESTERDAY”
#Login to file server to put the latest audit file there
ftp <IP> << cmd
bin
lcd /usr/sap/SID/DVEBMGS<SN>/log
cd /SID
put $YESTERDAYS_AUDIT_FILE
bye
3)Crontab entry to run this script daily:
crontab -e
#Sending Daily Audit Logs to XXXXX Server
0 7 * * * /tmp/FtpDailyAudit.sh 1>/dev/null 2>/dev/null