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.

Thomas Dickey
  • 76,765

2 Answers2

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" ]
l0b0
  • 51,350
-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

s.r
  • 361