LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-27-2007, 04:34 PM   #1
chnlinux
LQ Newbie
 
Registered: Jun 2007
Posts: 28

Rep: Reputation: 15
Reg the sftp script


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
 
Old 09-27-2007, 05:01 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Sincerely it was difficult to read your script, since it is very redundant (don't take this as a criticism... it is only a matter of styling and experience). Anyway, there is a typo here:
Code:
File2="$Fold$FilE.$d"
this brings to the wrong filename, as you can see in the error log.

Last edited by colucix; 09-27-2007 at 05:03 PM.
 
Old 09-27-2007, 05:27 PM   #3
chnlinux
LQ Newbie
 
Registered: Jun 2007
Posts: 28

Original Poster
Rep: Reputation: 15
Reg scftp script

Hi ,

Thanks for the timely help

Cheers/Sathish
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with reg exp script abefroman Programming 2 12-19-2005 04:53 PM
Nice surprise Kaffeine plays Reg 1 and Reg 2 disks 1kyle SUSE / openSUSE 1 10-10-2005 05:47 PM
sftp over shell script naughtymutt Linux - General 1 08-20-2004 06:56 AM
perl script reg expr confusion rajatgarg Programming 1 04-09-2004 04:49 PM
sftp script error JeRrYmAn Linux - Networking 1 11-27-2003 08:21 PM


All times are GMT -5. The time now is 10:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration