HI,
Please see the below script ,This script is to transfer file from one server to other server,When i ran the script i am getting the below error could any one help me in this
Error:
Connecting to nwstsap1.ea.com...
pkrishna@nwstsap1.ea.com's password:
File "/home/bsapna/ftp/.133218" not found.
Couldn't stat remote file: No such file or directory
Couldn't delete file: No such file or directory
Couldn't rename file "/home/pkrishna/ftp/.133218" to "/home/pkrishna/ftp/test-ftp.132824": No such file or directory
File ftp failed, please check mail for more details ...
Thanks/Chn
#!/bin/bash
echo "Starting Viatech FTP ..."
#Finding path for echo command
ECHO=`which echo`
#Finding path for sendmail
#SENDMAIL=`which sendmail`
MAIL=`which mail`
#Destination server host name
HOST="nwstsap1.ea.com"
HOST="nwstsap1.ea.com"
#source path below (Path on ERP server)
FOLD="/home/test/ftp/"
#Destination path below (Path on Tibco server)
DEST="/home/test/ftp/"
#FTP user name
USER=user1
#FTP password
#PASS=dr_viatech
#FTP file static part
FlName="test-ftp*"
err_file=/tmp/sftp_error.log
maillog=/tmp/sftp_mail.log
#Creating temporary log files:
touch $err_file
touch $maillog
#file name that has to be transfered
cd $FOLD
echo $FOLD
File=`ls -lt $FlName|head -2| tail -1|awk '{print $9}'`
echo $File
if [ -z $File ]
then
echo "File not found,Ftp unsuccessful, please verify location of file..."
>$maillog
$ECHO "From: sftp_script" >>$maillog
$ECHO "To:
vnagaraja@aa.com" >>$maillog
$ECHO "Subject: SFTP Failed" >>$maillog
$ECHO "" >>$maillog
$ECHO "Dear Team," >>$maillog
$ECHO "" >>$maillog
$ECHO " SFTP Failed from ERP Server." >>$maillog
$ECHO " File not found" >>$maillog
$ECHO " File not found" >>$err_file
$ECHO "" >>$maillog
$MAIL -s "ftpmail"
pkrishnan@aa.com < $maillog
rm -f $err_file
rm -f $maillog
exit 1
else
cd ~
d=`date|awk '{print $4}'|cut -c 1,2,4,5,7,8`
cp $FOLD$File $FOLD$File.$d
File2="$Fold$FilE.$d"
echo $File2
#Copy file from ERP server to Tibco server using sftllog
sftp -b /dev/stdin $USER@$HOST << END_SCRIPT > $err_file
cd $DEST
put $FOLD$File2
`ls -lt $FOLD$File2 >> /tmp/stderr_tmp`
rm $File
rename $File2 $File
bye
END_SCRIPT
## Check for sftp copy status & send mail
size=`cat /tmp/stderr_tmp | wc -l`
if [ $size = 1 ]
then
echo "Viatech File ftp successful, sending mail ..."
>$maillog
$ECHO "From: sftp_script" >>$maillog
$ECHO "To:
vnagaraja@aa.com" >>$maillog
$ECHO "Subject: SFTP Success " >>$maillog
$ECHO "" >>$maillog
$ECHO "Dear Team," >>$maillog
$ECHO "" >>$maillog
$ECHO " SFTP Success from ERP server." >>$maillog
$ECHO "" >>$maillog
$MAIL -s "ftp mail"
pkrishnan@aa.com < $maillog
rm -f $maillog
rm -f $FOLD$File
rm -f /tmp/stderr_tmp
rm -f $File2
exit
else
echo "File ftp failed, please check mail for more details ..."
>$maillog
$ECHO "From: sftp_script" >>$maillog
$ECHO "To:
vnagaraja@aa.com" >>$maillog
$ECHO "Subject: SFTP Failed" >>$maillog
$ECHO "" >>$maillog
$ECHO "Dear Team," >>$maillog
$ECHO "" >>$maillog
$ECHO " SFTP Failed from ERP Server." >>$maillog
$ECHO "" >>$maillog
cat $err_file >>$maillog
$ECHO "" >>$maillog
$MAIL -s "ftp mail"
pkrishnan@aa.com < $maillog
rm -f /tmp/stderr_tmp
rm -f $maillog
rm -f $File2
exit
fi
fi