Help with my weird script!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with my weird script!
# 1  
Old 06-15-2008
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"
# 2  
Old 06-15-2008
Are you using the ftp's return code to check for successful transfer or not ?
Use should parse the ftp log output and then decide the return status.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Weird difference in script execution

Hi, So I have a very simple script which loops over 5 times and prints the iterator value. #!/bin/sh START=1 END=5 for i in $(eval echo "{$START..$END}") do echo "$i" done If I save this script in a .sh file and run it in the terminal, the output I get is {1..5} (4 Replies)
Discussion started by: jamie_123
4 Replies

2. Shell Programming and Scripting

Traceroute script weird output

This script is giving weird output #!/bin/bash NETPATH=(`/bin/traceroute -n 4.2.2.2 | awk '{print $2}'`) for i in "${NETPATH}" do echo $i done The output: to 11.11.11.1 1.1.1.1 99.111.208.2 traceroute_test.sh traceroute_test.sh (7 Replies)
Discussion started by: thumbs
7 Replies

3. Shell Programming and Scripting

Weird problem in my shell script,please help me!!!

sqlLogftp_mov=$LOGDIR/logftp_mov_$mydate.log sqlplus -s $ORAUSER << EOF > $sqlLogftp_mov SET SERVEROUT ON @/$SCRIPTDIR/rep_comm_ext_tbl_load.sql EOF retorno=0 cnt=`grep -q 'ORA-' $sqlLogftp_mov | wc -l` if ; then retorno=1 echo 'Failure' sendEmailFalha exit 1 fi if ; then echo... (8 Replies)
Discussion started by: shyamaladevi
8 Replies

4. AIX

weird korn shell script

here is the one of the scripts: script1.kshfunction haha { print "calling haha" exit } script2.ksh. script1.ksh haha | tee -a /dev/null print "i am script 2" after launching the script2, the result: --------------------------------------------- calling haha i am script 2 ... (6 Replies)
Discussion started by: getter
6 Replies

5. Shell Programming and Scripting

Weird script behaviour !

Hello, I am getting an infinite loop from a script in Linux. Here is the last version of the script in question. As you can see I tried to define everything properly: #!/bin/ksh # Script to loop over a series of dates set -ex typeset -i start_date=20090701 typeset -i... (2 Replies)
Discussion started by: stavros
2 Replies

6. Shell Programming and Scripting

script acting weird..

Hi Guys, I have this script which is being called from another script, sh +x SCRIPTNAME. Now this script is failing saying the source file is missing. But i was able to see the source file was present. It was renamed and but somehow the source file is removed. There is no remove command in the... (1 Reply)
Discussion started by: mac4rfree
1 Replies

7. Shell Programming and Scripting

weird script in crontab

Hello here's the first line's of the code that works perfect on command line but not as a crontab job ??? crontab: 15 * * * * /root/scripts/checkclamd_mem.shscript: #!/bin/bash # Checks Memory of the Clamav-daemon and it's .pid file # restarts if over the LIMIT. Starts if pid file not... (3 Replies)
Discussion started by: nls mchn
3 Replies

8. Shell Programming and Scripting

Weird sed behaviour in script

I've written a small script to replace certain words in all the the files in a directory. #!/bin/sh #Get list of files to be edited file_list=`ls -p` for i in $file_list do echo "Processing $i" alteredi=`echo "$i" | sed -e 's/\//d/'` if then if then #actual altering (2 Replies)
Discussion started by: Peetrus
2 Replies

9. UNIX for Dummies Questions & Answers

Weird Behavior of a Script

ok, there's a script i'm working on written in shell programming. #!/bin/sh this script is written to spit out the contents of certain variables inside of it so the output looks something like this: server01=89 server02=69 server03=89 server04=76 now, when i run this script from the... (4 Replies)
Discussion started by: SkySmart
4 Replies

10. UNIX for Dummies Questions & Answers

Weird script

I need a script to do the following and have no idea how to do it...can someone help? I need to start Sql*Plus, load a query, say "unmatched.sql", run the query, then load unmatched.sc and run it, then print the output file that unmatched.sc created... any help greatly appreciated. Duckman (2 Replies)
Discussion started by: Duckman
2 Replies
Login or Register to Ask a Question