1

In my environment, we'll be receiving files from clients into our Sftp server. Sftp processes the files, and moves it to another tool, by appending the file size at the end of the file name. For example, samplefile.20150706 of size 1024 would be created as samplefile.20150706.1024.

If file size and name (the last part after .) matches, our tool will pick the file and send it to ETL. If the file stays in that place for more than an hour (not processed due to unmatched size and name), the tool will send us alerts, as files are over an one hour old.

I'm looking for commands, which will extract the last part of the file name and compare it with file size, and eventually delete the file.

4

Get the file size:

size="$(stat --printf="%s" "$path")"

Get the path without the last extension:

path_without_extension="${path%.*}"

Compare the two:

[ "${path_without_extension}.${size}" = "$path" ]
-1

ls -l | awk '{print $5}' gives your file size
echo file_name | awk -F"." '{print $3}' gives you file size extracted from name.

a=`ls -l | awk '{print $5}'` b=`echo file_name | awk -F"." '{print $3}'` if [ $a -eq $b ] then echo "you can do your processing here" fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.