Sponsored Content
Top Forums Shell Programming and Scripting To check wheather a file is downloaded completely or not Post 302450082 by felipe.vinturin on Wednesday 1st of September 2010 01:18:32 PM
Old 09-01-2010
Hi VPV0002,

We have two options:
1. Use the function below which will base on the file size:
Code:
#!/bin/ksh

numOfRetries=3
sleepTime=3

transfFileFinished ()
{
	valFilePath="${1}"
	if [ ! -f "${valFilePath}" ]
	then
		echo "ERROR: File does not exist: [${valFilePath}]. Exit 1."
		exit 1
	fi
	
	oldFileSize=`ls -l "${valFilePath}" | awk '{print $5}'`
	while true
	do
		if [ ${numOfRetries} -eq 0 ]
		then
			echo "File transfer ok. Max number of retries reached: [${numOfRetries}]"
			return 0
		fi
	
		currFileSize=`ls -l "${valFilePath}" | awk '{print $5}'`
		if [ ${oldFileSize} -eq ${currFileSize} ]
		then
			# If reaches here ${numOfRetries} times, so the file is ok
			numOfRetries=`expr ${numOfRetries} - 1`
		else
			echo "File size differ. Old File Size: [${oldFileSize}] - Curr File Size: [${currFileSize}]."
		fi
		
		echo "Old File Size: [${oldFileSize}] - Curr File Size: [${currFileSize}] - Retry: [${numOfRetries}] - Sleeping: [${sleepTime}]..."
		sleep ${sleepTime}
		oldFileSize=`ls -l "${valFilePath}" | awk '{print $5}'`
	done
}

transfFileFinished "./TestFile.txt"

2. From where you are sending the file, send the file with a ".tmp" in the end of the filename and after the transfer finished, use the FTP rename command and rename it to the original filename, so your ksh script will process it.

Hope it helps.

Regards.

Last edited by felipe.vinturin; 09-01-2010 at 04:38 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

HELP! Accidentally downloaded .gz file non-binary

Let me start by saying I am at a VERY beginner level in terms of UNIX/FTP/etc. Someone loaded a file onto a server for me and zipped it using gzip. I accidentally downloaded the file without using "binary". I now have a "filename.txt.gz" sitting on my computer that I need to unzip. Is... (2 Replies)
Discussion started by: UDcc123
2 Replies

2. Linux

How I will check wheather my linux benchmark results are OK

My system bench mark results INDEX VALUES TEST BASELINE RESULT INDEX Arithmetic Test (type = double) 2541.7 876123.7 344.7 Dhrystone 2 without register variables 22366.3 5411602.3 ... (1 Reply)
Discussion started by: chandra s
1 Replies

3. UNIX for Advanced & Expert Users

Using FTP to check whether file is completely FTP... plz find the description below

Hi, We have some clients who will place huge files in to one of the remote server. And the shell script written in our local server to retrieve client files (using FTP) placed on one of the remote server of ours by clients. My question Is there any FTP command/script to check from my local... (1 Reply)
Discussion started by: nmsrao
1 Replies

4. UNIX for Advanced & Expert Users

Count total file downloaded using FTP

Hi All, I'm developing a FTP script as below: ftp -v -n <IP_ADDRESS> << EOF user avery jSqaqUU2 lcd /directory/folder/ ascii prompt mget * bye EOF I would like to enhance the script to count the total file downloaded. For example, once the script run i want the message "Total <n>... (1 Reply)
Discussion started by: cas553
1 Replies

5. Shell Programming and Scripting

Check if file is loaded completely and then process the file

I need to write a script which checks for files loaded into a folder (files are loaded by ftp from other server) and process the file only if the file is loaded completely. if the file is not complete in the current run, it must be processed in the next run. Any suggestions would be welcome... (2 Replies)
Discussion started by: kalyan381
2 Replies

6. UNIX for Advanced & Expert Users

Check EOF char in Unix. OR To check file has been received completely from a remote system

Advance Thanks. (1) I would like to know any unix/Linux command to check EOF char in a file. (2) Or Any way I can check a file has been reached completely at machine B from machine A. Note that machine A ftp/scp the file to machine B at unknown time. (5 Replies)
Discussion started by: alexalex1
5 Replies

7. UNIX for Advanced & Expert Users

script to check if file was downloaded

I want to create a script to check if a file was downloaded into a folder. if it was i dont want to re-download it. The requirement is as follows. The first time the file (filename: A) is downloaded, it is renamed by stripping off part of the filename to filename A22. The second time an... (1 Reply)
Discussion started by: wizardofoz
1 Replies

8. Programming

how to copy downloaded file into my source file folder (putty/unix)

I need to "Ensure that when you download libchat.a from the VLE you have copied it to the same folder on ius as your source files. You then refer to the library (and the libraries it needs) with: gcc -o outputfile sourcefile.c -L. -lchat -lsocket -lnsl" But I have no idea what this means! (I... (2 Replies)
Discussion started by: fakuse
2 Replies

9. Shell Programming and Scripting

extract fields from a downloaded html file

I have around 100 html files and in each html file I have 5-6 such paragraphs of a company and I need to extract the Name of the company from either the one after "title" or "/company" and then the number of employees and finally the location . <div class="search_result"> <div... (1 Reply)
Discussion started by: gubbu
1 Replies

10. UNIX for Dummies Questions & Answers

[Solved] Downloaded file is not correct format

Hi, Recently we migrated an application in HP UX to Linux. The files(scripts & logs)download from HP UX coming in a formatted way in MS notepad. However the files in Linux are not in correct format in MS notepad(No spaces , some spl symbols like square).We tried both ASCII and binary but no... (2 Replies)
Discussion started by: nag_sathi
2 Replies
exit(1) 							   User Commands							   exit(1)

NAME
exit, return, goto - shell built-in functions to enable the execution of the shell to advance beyond its sequence of steps SYNOPSIS
sh exit [n] return [n] csh exit [ ( expr )] goto label ksh *exit [n] *return [n] DESCRIPTION
sh exit will cause the calling shell or shell script to exit with the exit status specified by n. If n is omitted the exit status is that of the last command executed (an EOF will also cause the shell to exit.) return causes a function to exit with the return value specified by n. If n is omitted, the return status is that of the last command exe- cuted. csh exit will cause the calling shell or shell script to exit, either with the value of the status variable or with the value specified by the expression expr. The goto built-in uses a specified label as a search string amongst commands. The shell rewinds its input as much as possible and searches for a line of the form label: possibly preceded by space or tab characters. Execution continues after the indicated line. It is an error to jump to a label that occurs between a while or for built-in command and its corresponding end. ksh exit will cause the calling shell or shell script to exit with the exit status specified by n. The value will be the least significant 8 bits of the specified status. If n is omitted then the exit status is that of the last command executed. When exit occurs when executing a trap, the last command refers to the command that executed before the trap was invoked. An end-of-file will also cause the shell to exit except for a shell which has the ignoreeof option (See set below) turned on. return causes a shell function or '.' script to return to the invoking script with the return status specified by n. The value will be the least significant 8 bits of the specified status. If n is omitted then the return status is that of the last command executed. If return is invoked while not in a function or a '.' script, then it is the same as an exit. On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a vari- able assignment. This means that tilde substitution is performed after the = sign and word splitting and file name generation are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
break(1), csh(1), ksh(1), sh(1), attributes(5) SunOS 5.10 15 Apr 1994 exit(1)
All times are GMT -4. The time now is 01:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy