The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Weird Awk issue Khoomfire UNIX for Advanced & Expert Users 17 04-14-2008 08:13 AM
HP-UX weird FTP ? IngmarMeins HP-UX 10 11-29-2005 08:22 PM
weird stuff woofie Windows & DOS: Issues & Discussions 4 11-16-2004 07:41 PM
Weird Question rahulrathod UNIX for Advanced & Expert Users 4 10-21-2004 05:48 AM
Weird script Duckman UNIX for Dummies Questions & Answers 2 03-14-2001 01:53 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 06-15-2008
kdyzsa kdyzsa is offline
Registered User
  
 

Join Date: May 2008
Posts: 14
Help with my weird script!

So I have this script titled "testing.sh"
#!/bin/ksh

#PROGRAM INITIALIZATION

HomeDir=/home/sap/gl/ftp
server=testftp01
userid=ftp_uatollmsgbus
password="f&p53715"
MSGLOG=${HomeDir}/msglog.txt
FTPLogTmp=${HomeDir}/testing.tmp
FTPLogFile=${HomeDir}/testing.log
FTPFILE=${HomeDir}/testing.ftp
FtpErrIni=/home/sap/SQL/ftp_error.ini
Recipient="test@test.com"
FileSize=`du -ks /home/sap/gl/ftp/${TransferFile} | cut -d/ -f1`
TransferFile="sap_exch_rate.txt"

#----------------------------
# Build FTP Script
#----------------------------

touch $FTPFILE

echo "open ${server}" > $FTPFILE
echo "user ${userid} ${password}" >> $FTPFILE
echo "cd /ftp_uatollmsgbus/OOCL/in/SAP_BookRate_UIF" >> $FTPFILE
echo "ascii" >> $FTPFILE
echo "prompt off" >> $FTPFILE
echo "lcd $HomeDir" >> $FTPFILE
echo "ls ${TransferFile}" >> $FTPFILE
echo "mput ${TransferFile}" >> $FTPFILE
echo "bye" >> $FTPFILE

#------------------------------
# FTP ERROR CHECKING FUNCTION
#------------------------------

f_CheckFtpErr()
{
tr [a-z] [A-Z] < ${FTPLogFile} > ${FTPLogTmp}

count=1
error=0
numlines=`cat ${FtpErrIni} | wc -l`

while [ ${count} -le ${numlines} ]; do
ftp_err=`head -${count} ${FtpErrIni} | tail -1`
if [ `grep -c -i "${ftp_err}" ${FTPLogTmp}` -gt 0 -o `grep -c -i "cannot find the file" ${FTPLogTmp}` -gt 0 ]
then
error=`expr ${error} + 1`
fi
count=`expr ${count} + 1`
done
}

#--------------------------------
# FTP TRANSFER AND ERROR CHECKING
#--------------------------------

echo "Starting to FTP sap_exch_rate.txt to testftp01" >> $FTPLogFile
ftp -n < $FTPFILE > $FTPLogFile
f_CheckFtpErr

#-----------------------------------------
# CHECK FOR FTP ERROR || MAIL NOTIFICATION
#-----------------------------------------

# IF THERE IS NO ERROR

if [ ${error} -eq 0 ]
then
#MAIL NOTIFICATION
echo "Dear All," > $MSGLOG
echo "" >> $MSGLOG
echo "The sap_exch_rate.txt file has been" >> $MSGLOG
echo "successfully FTP to server testftp01" >> $MSGLOG
echo "Please check." >> $MSGLOG
echo "" >> $MSGLOG
echo "Thanks." >> $MSGLOG
echo "" >> $MSGLOG
echo "" >> $MSGLOG
echo "File size of sap_exch_rate.txt is $FileSize kilobytes" >> $MSGLOG
mailx -s "FTP of sap_exch_rate.txt file to testftp01 completed successfully" $Recipient < $MSGLOG
echo "testftp01 FTP SUCCESSFUL"

# IF AN ERROR OCCURS

else
#MAIL NOTIFICATION
echo "HKCTR," > $MSGLOG
echo "" >> $MSGLOG
echo "Error has occurred while transferring" >> $MSGLOG
echo "sap_exch_rate.txt file." >> $MSGLOG
echo "Please contact the MNLSAP support for" >> $MSGLOG
echo "this week to fix the problem" >> $MSGLOG
echo "" >> $MSGLOG
echo "Thanks." >> $MSGLOG
echo "" >> $MSGLOG
echo "" >> $MSGLOG
echo "Error Log:" >> $MSGLOG
echo "" >> $MSGLOG
echo "Error: `head -3 ${FTPLogFile} | tail -1" >> $MSGLOG
echo "" >> $MSGLOG
echo "Script/Job name: testing.sh" >> $MSGLOG
mailx -s "Error in testing.sh script" $Recipient < $MSGLOG
echo "Error in testftp01 ftp"
fi

rm $FTPLogFile
rm $FTPFILE
rm $FTPLogTmp
#****************************END*OF*PROGRAM*******************************#

It basicallytransfers one text file from one server to another. My problem is this, once I run it, the file I'm looking for is successfully transferred to the other server, That's ok right? But after that, I erased my file from the home server and try to transfer it again, I get the screen that "file is not available" but an email is sent to me! saying that the file was succssfuly transferred. This is odd because the file was already deleted! how can it be transferred, but when I erase the file from the destination server, and I run the program again, I get the correct error message saying that the file is not found and an email saying that the file cannot be found.

Does anyone know how to fix this? meaning that once that file is in the destination server and I erase it from the home server and I try to run the program again, the output email should be that the file cannot be found NOT "file successfully transferred"
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:39 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0