Random files do not FTP in the shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Random files do not FTP in the shell script
# 1  
Old 06-29-2006
Error Random files do not FTP in the shell script

The following script is used to loop through files in the /tmp directory and transfer those files onto another server.
However, some of the files do not transfer. It is very random when the transferring is done (i.e. one of the files won't transfer then next time, that one will transfer and another won't transfer.)

Any suggestions as to why? Thanks in advance!


#! /bin/sh -x

# Print date into log file
date



#associate parameters to p variables
p1=$1
p2=$2
p3=$3
p4=$4


#echo parameters into log file
echo ""
echo "Input parameters are: param1(Oracle User/Password) = ********"
echo " param2(User Acct Num) = $p2"
echo " param3(Requestor Name) = $p3"
echo " param4(Request ID) = $p4"
echo ""

#set up Unix script variables
LOCAL_DIR=$SRS_TOP/sql
TMP_DIR=$APPLTMP
LOG_FILE=l$p4.req
FTP_SERVER=$5
FTP_LOGON=$6
FTP_PASS=$7
TIMESTAMP=`date '+%m%d%y%H%M%S'`

#now do the xfer to the getpaid server

echo ""
echo "FTP parameters are: SERVER = $FTP_SERVER"
echo " LOGIN = $FTP_LOGON"
echo " PASS = *********"
echo " TEMP = $APPLTMP"
echo " REQUEST = $p4"
echo ""

FTP_OUTFILE=ar*.txt

cd $APPLTMP

#Verify Host filename(s) and put into Local_Dir list
for file in $FTP_OUTFILE do
if test -f $file; then

TEMP_FILE=/tmp/ftp$p4$file


#Verify Host Directory exists
if test -d "$TMP_DIR"; then
HOST_DIR=$TMP_DIR;
else
echo "Invalid Host Dir [$TMP_DIR]"
exit 1;
fi



#Set success/failure flag
TESTCOND=0


#Create the ftp script
echo "open $FTP_SERVER" >> $TEMP_FILE

echo "user $FTP_LOGON $FTP_PASS" >> $TEMP_FILE

echo "ascii" >> $TEMP_FILE

echo "prompt" >> $TEMP_FILE

echo "cd getpaid\nlcd $TMP_DIR" >> $TEMP_FILE

echo "put $file" >> $TEMP_FILE

echo "bye\n" >> $TEMP_FILE


#11/21/02 - JEM - Get rid of two temp files used to capture problems
rm /tmp/ftp.err /tmp/ftp.failed


#Execute the FTP script created
#11/21/02 - JEM - Redirect the message output
if ftp -n < $TEMP_FILE > /tmp/ftp.err 2>&1;
then
echo "";
else
echo "ftp command failed!\n"
exit 1;
fi


#11/21/02 - JEM - Added next 7 lines because the test above does not really catch errors
grep -i 'Connection refused' /tmp/ftp.err > /tmp/ftp.failed
grep -i fail /tmp/ftp.err >> /tmp/ftp.failed

if [ ! -s /tmp/ftp.failed ]; then
echo ""
else
cat /tmp/ftp.err
exit 1
fi


if [ "$?" -eq 0 ]
then
echo " "
echo "*** DONE TRANSFER OF OUTPUT FILE ***"
else
echo " "
echo "Transfer of Output File Failed!"
echo "Call Tech Support!"
echo "*** Exitting Script On Failure!!!************"
exit 1
fi


else
echo "Invalid file [$APPLTMP/$file]"
exit 1;
fi

cp /tmp/ftp.err /tmp/ftp$file
cp /tmp/ftp.failed /tmp/ftp$file

done
# 2  
Old 06-29-2006
The files in /tmp may still be open/being built - then the next time you run, those are okay and transfer and some other file is in the same state - open or being built.

Check the process that builds these files or for any processes that may have them open - if the file is open, you may not want to transfer until they are static.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

FTP in shell script and selecting files for upload

Hi, Im a newbie with programming and shell scripting. Im running OSX/Mac and Darwin. I would like to create a shell script that would : 1. Search a Volume and directory (including subdirectories) for a file that : * filename ends with ”_Highres.pdf” and * the file creation date of... (8 Replies)
Discussion started by: NickeZ28
8 Replies

2. Shell Programming and Scripting

shell script to ftp multiple files

Hi, i use the below script to send a single file to remote server from linux. ftp -nvi <<!EOF open $Host_name user $USER_ID $PWD binary mput $file_name quit !EOF (where i... (2 Replies)
Discussion started by: pradebban
2 Replies

3. Emergency UNIX and Linux Support

Shell script to get all the files from FTP server

Hi Guru's, I am new to UNIX. my requirement is to log on to FTP server and get all the .txt files. i have developed one script by searching some forums but getting error and not able to fix them. pls see below code. ftp -i-n<<EOF open $FTP_HOST... (30 Replies)
Discussion started by: arund_01
30 Replies

4. UNIX for Dummies Questions & Answers

ftp files from one server to another using shell script

Hi Guys Any Help I have created a spool file that i need to copy onto another server using FTP in a shell script both servers are linux (3 Replies)
Discussion started by: itai
3 Replies

5. UNIX for Advanced & Expert Users

Shell script to ftp files from windows to unix

Hi , I need to ftp some input files from windows to unix server.All the files will be saved in the C drive in my machine.Currently all these files are transferring manually to the unix server.I need to write a shell script which ftp the files from windows to unix box.When I searched in the forum i... (1 Reply)
Discussion started by: kavithakuttyk
1 Replies

6. Shell Programming and Scripting

shell script to auto process ten random files and generate logs

Hello member's I'm learning to script in the ksh environment on a Solaris Box. I have 10 files in a directory that I need to pass, as input to a batch job one by one. lets say, the files are named as follows: abcd.txt ; efgh.bat ; wxyz.temp etc. (random filenames with varied extensions ).... (1 Reply)
Discussion started by: novice82
1 Replies

7. Shell Programming and Scripting

Getting a list of files on an ftp, via shell script...

G'day, I was wanting to write a shell script that checks an ftp server for the presence of new files, then get those files. In so much as the get, this is pretty straight forward, but I cannot work out how to get a list of files to check. Is it possible for a shell script to get the output of... (1 Reply)
Discussion started by: Elric of Grans
1 Replies

8. Shell Programming and Scripting

FTP random files

Hello everyone, What I'm trying to do is figure out how to ftp a set of random files each day about 50 or so maybe more or less. I have a folder on my server that gets about 1000 or so new files each day, each with today's date in the file name. We just want to take a sample each day for... (3 Replies)
Discussion started by: whegra
3 Replies

9. Shell Programming and Scripting

Random parameters passing in FTP script

Hi I have a question. In the FTP script if we are passing all the required value like Hostname, username, password, Action(put or get), Filename, & mode(ascii or binary) through parameters then we have to pass these in the exact orders in which they are taken like if we defined Username=$2... (2 Replies)
Discussion started by: sourabhshakya
2 Replies

10. Shell Programming and Scripting

ftp files inside a shell script

I have a shell script where I am trying to ftp some files but I get the error message "EOF unclosed" every time the script reaches the ftp section. Here is how my script is written. #more code up here rm -f $object >> $LOG_FILE 2>&1 fi #end of if done #end of for loop ... (5 Replies)
Discussion started by: matrix1067
5 Replies
Login or Register to Ask a Question