FTP Client helps bash + awk


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users FTP Client helps bash + awk
# 1  
Old 05-03-2012
Question FTP Client helps bash + awk

FTP Client helps bash + awk

Good afternoon,
Dear I have a script that performs a file sent to another server the process is simple but moving large volume of information is run through crontab every 30 minutes, is that the scritp connected to Windows servers, I have unix (solaris 5.10), the problem is that it freezes and although I tried to find the causes and capture the error codes do not get this last thing I turn to you seeking guidance, I have already evaluated points.
• Restrictions antivirus on Windows systems (I found the eliminated)
• Failures ftp services (corrected)
Stress tests conducted with a filezilla server, but can not replicate the cause of the problem. I hope it is useful to other users
Code:
#!/bin/bash
#--------------------------------------------------------------------------#
#Since: 27-AGO-2009                                                        #
#Autor Reingeniería: Arnulfo Araúz K | DTB!                                #
#Fecha: 09-Abril-2012                                                      #
#--------------------------------------------------------------------------#

proceso="gsm_smss_control14"
echo $HOME/.bash_profile>/dev/null
FECHA=`date '+%Y%m%d%H%M%S'`

#Inicio de pruebas en desarrollo se configura un servidor en filezilla server 
PATH_MONEYMAP_MSC="/datafiles/PAN/DS_MSC/TX3/RAWDATA/INPUT"
PATH_MONEYMAP_SMSGW="/datafiles/PAN/DS_HUAWEI/TX3/RAWDATA/INPUT"
EL_HOST="10.1.0.1"
USUARIO="aaa"
PASSWORD="123"
#Para Fin Prueba


PATH_MDR_MSC=$GSM_HIS_HISTORY
PATH_MDR_SMSGW=$SMSS_HIS_HISTORY
mascara_gsm="TTFILE*"
mascara_smssgw="SMCHWSGPA*"

enviar_lotes()
{
if [ $# -ne 4 ]
then
  echo "Usa: $1 $2 $3 $4"
  exit
fi

cd $1
  FTPLOG=$MDR_LOG/${proceso}_FTP_${FECHA}.log
  ARCLOG=$MDR_LOG/${proceso}_FTP_Fallos_Archivos_${FECHA}.log
  FTP_TMP=$MDR_LOG/${proceso}_FTP_TMP_${FECHA}.log
  echo "Archivos que no se pudieron enviar a la fecha ${FECHA} nombre log $ARCLOG"
  echo >$ARCLOG
  echo "Log del FTP $FTPLOG"
  echo "Log del FTP $FTPLOG">$FTPLOG
for archivo in  $2
do
  if [ -f "$archivo" ]
	  then
	  file_size=`ls -l $archivo| awk '{print ($5) }'`
	  echo "Inicia envio de archivo $archivo con tamaño ${file_size} byte" | tee -a "$FTPLOG"
echo `ftp -n -v -i $EL_HOST<<END_SCRIPT 
		quote USER $USUARIO
		quote PASS $PASSWORD
		binary
		cd  $3
		put $archivo
		quit
END_SCRIPT`>"${FTP_TMP}"
	echo $FTP_TMP | tee -a "$FTPLOG"
	f=$(more ${FTP_TMP} | tail -1 | grep "Not connected" | grep -v grep | wc -l) 
	if [ $f -eq 1 ]
	then
		echo "Fallo del FTP Conexión rechazada: login failure,Ip ${EL_HOST}, Archivo ${archivo},tamaño ${file_size} byte,fecha `date '+%Y%m%d%H%M%S'`" | tee -a "$FTPLOG"
		#<realizar sus acciones aquí cuando no funciona FTP>
		echo $archivo | tee -a "$ARCLOG"
		else
		#trap ftp code
		f=$(more ${FTPLOG} | grep 226 | grep -v grep | wc -l) 
		if [ $f!=0 ]
		then
			echo "éxito de FTP,Ip ${EL_HOST}, Archivo ${archivo},tamaño ${file_size} byte,fecha `date '+%Y%m%d%H%M%S'`" | tee -a "$FTPLOG"
			#<realizar sus acciones aquí con éxito de FTP>		
			echo Moviendo archivo ${archivo%TXT.zip}* a $4 | tee -a "$FTPLOG"
			mv ${archivo%TXT.zip}* $4
			echo $archivo >>$PATH_DIRARCHIVOLOG
		else
		f=$(more ${FTPLOG} | grep 530 | grep -v grep | wc -l) 
		if [ $f!=0 ]
		then
			echo "Fallo FTP: login failure,Ip ${EL_HOST}, Archivo ${archivo},tamaño ${file_size} byte,fecha `date '+%Y%m%d%H%M%S'`" | tee -a "$FTPLOG"
				#<realizar sus acciones aquí cuando no funciona FTP>
				echo ${archivo} | tee -a "$ARCLOG"
		else
		f=$(more ${FTPLOG} | grep 552 | grep -v grep | wc -l) 
		if [ $f!=0 ]
		then
			echo "Fallo FTP: problema de espacio en disco,Ip ${EL_HOST}, Archivo ${archivo},tamaño ${file_size} byte,fecha `date '+%Y%m%d%H%M%S'`" | tee -a "$FTPLOG"
			#<realizar sus acciones aquí cuando no funciona FTP>
			echo ${archivo} | tee -a "$ARCLOG"	
		else
		f=$(`more FTPLOG | awk '/${archivo}/{print $61 $62}'`)
		if [ $f -eq $file_size ]
		then
			echo "Fallo FTP: No se transfirio completo el archivo a pasar ${archivo} con tamaño ${file_size} byte se transfirieron $f a la fecha `date '+%Y%m%d%H%M%S'`" | tee -a "$FTPLOG"
			echo ${archivo} | tee -a "$ARCLOG"
		else
			echo "Fallo FTP: host (connection) might have problems,Ip ${EL_HOST}, Archivo ${archivo},tamaño ${file_size} byte,fecha `date '+%Y%m%d%H%M%S'`" | tee -a "$FTPLOG"
					#<realizar sus acciones aquí cuando no funciona FTP>
			echo ${archivo} | tee -a "$ARCLOG"
		fi
		fi
		fi
		fi
	fi
else
		   echo "No existen archivos para las mascaras ${1}/TXT.zip" | tee -a "$FTPLOG"
fi
done
rm ${FTP_TMP}
}


principal()
{
                echo "-----------------------------------------------------------------------------------------"
                echo "-          Proceso que automatiza el envio a MoneyMapp de los                           -"
                echo "-          Archivos de entrada a la mediacion(GSM y SMSS) Para el Control 14            -"
                echo "-----------------------------------------------------------------------------------------"
                echo "                                                                                         "
        echo "Starting Process matcargar_gsm_smss_control14..."
                echo $0 lanzado en ...: $(date)
        echo Inicio...
        echo 1: Enviando lotes MSC...
                destinoMSC=$PATH_MDR_MSC/PROCESADOS
                enviar_lotes $PATH_MDR_MSC $mascara_gsm $PATH_MONEYMAP_MSC $destinoMSC
                echo "   Envio de archivos finalizado para el directorio: " $PATH_MDR_MSC
        echo "                                                  "
        echo 5: Enviado lotes SMSGW...
                destinoSMSGW=$PATH_MDR_SMSGW/PROCESADOS
                enviar_lotes $PATH_MDR_SMSGW $mascara_smssgw $PATH_MONEYMAP_SMSGW $destinoSMSGW
                echo "   Envio de archivos finalizado para el directorio: " $PATH_MDR_SMSGW
        echo "                                                    "

                echo Se finalizo el envio de lotes a Moneymapp, y la movida de los mismos !!!
                echo $0 terminado en ...: $(date)
                echo $0 quedara dormido, luego de 30 minutos se levantara de nuevo !!!
}
principal
exit

Moderator's Comments:
Mod Comment Code tags for code, please.
# 2  
Old 05-03-2012
Freezing could simply be network problems, as well.
# 3  
Old 05-03-2012
Will investigate this possible effect, but no way that this part of code can react to a network problem, because it just stays stuck in the ftp log that I have
Start sending file-1268_12_5_01.PROC.zip archivo.2_02_ 48813 byte sized
Code:
echo `ftp -n -v -i $EL_HOST<<END_SCRIPT 
		quote USER $USUARIO
		quote PASS $PASSWORD
		binary
		cd  $3
		put $archivo
		quit
END_SCRIPT`>"${FTP_TMP}"


Last edited by arnolkat; 05-03-2012 at 07:28 PM..
# 4  
Old 05-03-2012
Is the FTP client program still running though, i.e. the ftp process itself?
# 5  
Old 05-03-2012
Correct the client begins sent, then just freezes or finishes sending or send any error message that can capture, if you know how I do it by any chance or you have this code snippet.
# 6  
Old 05-03-2012
That's a useless use of backticks there. If it appears on the screen, you don't need echo to put it anywhere else.

And the END_SCRIPT, I'm not sure that's working right. The code below it might simply be being skipped.

And you haven't captured standard error, so error messages are being lost.

Try this:

Code:
ftp -n -v -i $EL_HOST >logfile 2>errfile <<END_SCRIPT 
		quote USER $USUARIO
		quote PASS $PASSWORD
		binary
		cd  $3
		put $archivo
		quit
END_SCRIPT

# 7  
Old 05-03-2012
With filezilla when you performed the tests if he was having a 300 mg file and closed the ftp server connection hangs with code so as you indicate, with the cast returns the error.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

AIX FTP client

I am trying to transfer logs from Aix 6.1 to a linux appliance but it is not happening from last one month if i execute the batch command by command i can execute well but if i do it in shell script it is stuck without any error. Any one know how to generate a FTP client trace to know the issue... (10 Replies)
Discussion started by: ra8ul
10 Replies

2. HP-UX

Disable GSSAPI when using an FTP client?

We have two HP-UX machines, both are B.11.31. When I FTP from the HP-UX boxes to a remote IBM server,- HP-UX 1: Connected to xxxx. 220-FTPD1 IBM FTP CS V1R12 at R2, 12:24:39 on 2013-08-30. 220 Connection will close if idle for more than 15 minutes. Name (xxxx:user): HP-UX 2:... (2 Replies)
Discussion started by: CaptNemo
2 Replies

3. Red Hat

Implement FTP server on RHEL server without using FTP client

We have RHEL 5.8 in our environment, I had a query whether we can implement an FTP server using vsftpd package and Linux configurations like setsebool without using any external FTP clients like FileZilla etc. I am very confused on this. The FTP functionalities that should be present are download &... (3 Replies)
Discussion started by: RHCE
3 Replies

4. UNIX for Advanced & Expert Users

Dummy FTP Client!

We're just about to start testing a new server build. The application has many FTP/SFTP connections going to different servers. I'd like to temporarily replace the FTP/SFTP binaries with a mock version that will allow us to run all our production code as is, but will prevent the FTPs from actually... (1 Reply)
Discussion started by: JerryHone
1 Replies

5. Solaris

A good ftp client

Can anyone please suggest a agood ftp client(GUI) which would support sftp ...on solaris. I badly need it. I keep doing the transfers frequently, and some of them are binary and I am not sure how I change the mode to binary. To avoid this and other hassles, it would help if i have a GUI client. ... (6 Replies)
Discussion started by: Naanu
6 Replies

6. UNIX for Advanced & Expert Users

Command line FTP Client

I'm looking for a FTP client that is similar to NCFTP in that I can run a full ftp command in one line without needing to access the client first then typing the ftp commands. Very simple request but I can't find any other tool like that, I have downloaded Kermit thinking I can use it to tranfer... (3 Replies)
Discussion started by: tamkag
3 Replies

7. Linux

ftp server/client buffers

Hi all, and again, I need help by you :-) I am using RH Advanced Server 2.1 with the defaukt wu-ftpd deamon. Now i want to tune the speed of my ftp transfers, but for this I need to increase the buffers for reading/writing from/to a filesystem and the sending/receiving buffers of the network.... (1 Reply)
Discussion started by: malcom
1 Replies

8. UNIX for Dummies Questions & Answers

ftp command line client

Hi! Does anyone of you know another good ftp command line Client like Midnight Commander? (not /usr/bin/ftp) Thanks. (5 Replies)
Discussion started by: donald1111
5 Replies

9. UNIX for Dummies Questions & Answers

Darwin + XFree86 FTP Client

Does anyone know of a decent Darwin + XFree86 FT client package? Obviously a precompiled file is better than binary, but I'll take what I can get. (10 Replies)
Discussion started by: chenly
10 Replies

10. UNIX for Dummies Questions & Answers

FTP Client

Is there any ftp CLIENT(either freeware or sharware) can support passive mode else ncftp? Thanks! (2 Replies)
Discussion started by: coolmans
2 Replies
Login or Register to Ask a Question