Sample Unix/Linux sftp shell scripting to read and xml, find data file, and transfer to another server
- Linux Bash script – How to read a linux file – script
- Linux Unix Shell script – How to add integers in bash? – sample
- How To Create Ssh Trust Connection Between Servers Or Client-Server To Connect Without Password?
- How To Extract,Using Bash/Unix/Linux Shell Scripting, The Oracle Data Like Excel Report And Send As Email Attachment?
- Linux / Unix / Bash Help: A check to see if a wildcard expression of files/folders exists or not
The following linux bash script shows sample sftp shell script to read and xml, find data file, and transfer to another server.
You must have set the ssh trust setup between the servers. By setting up the trust, you do not need to input a password.
#**************************************************************************************************
#
# Script Name: sftpdata.sh
#
# Developed by Jay
#**************************************************************************************************
# Sample Script unix linux sftp – reading xml and send the data file from one server to another
# Parameter: The first parameter must be the XML Filename
#
# Usage: sftpdata.sh abcd.xml
#**************************************************************************************************
#
SFTPUID="<uid>"
SFTPPWD="<pwd>"
SFTPSVR="<server>"
LOCATION="/home/notesbit/test" # change to correct position
XMLFILE="${LOCATION}/$1" # It should be XMLFILE="${LOCATION}/$1"
#echo "XMLFILE=${XMLFILE}" #Test to see the filename
DATLIST=`grep -i "\.dat" ${XMLFILE} ‘ sed -e ‘s/<[^>]*//g‘ ‘ sed ’s/>//g’` # This removes xml tags and gets only the *.dat file in a list
for filename in ${DATLIST} # List is read in loop
do
sftp -b -oPort=22 ${SFTPUID}@${SFTPSVR} << EOF
put $filename
echo $? # this gives return status
quit
EOF
done
If you do not setup any trust, you need to use expect utility. If you do not have “expect” utility, please install it in the linux machine.
will install the utility. You can modify the following script suitably to replace
spawn sftp -b batchfile user@ipaddress
expect "password:"
send "userpassword\n";
interact

Comments
No comments yet.