By pass a process in a Shell Script on file size

I wish to by pass a process if the file is over a certain size?
not sure this makes sense

current bit of the script below

#if we are bypAssing the OCR
if [ $BYPASS_OCR == "Y" ] ; then
   echo Bypassing HOTFOLDER OCR
   HOT_FOLDER_DIR=$BATCH_POST_OCR_DIR;

potential change below? would this work would I need to declare FILE_SIZE somehow?

if [ $BYPASS_OCR == "Y" and FILE_SIZE > 1000kb ] ; then
   echo Bypassing HOTFOLDER OCR
   HOT_FOLDER_DIR=$BATCH_POST_OCR_DIR;

The logics are OK, but the syntax is not:

  • and is not a shell keyword; try -a (although deprecated)

  • FILE_SIZE will not be expanded; use with $ sign

  • > is being interpreted as an output redirection; even if escaped will be a lexicographical comparison; use -gt for integer comparison.

  • 1000kb is not an integer - even 90 (as a string) will compare "greater". Use 10000000.

Somehow, yes. Else it is unset and interpreted as zero.

1 Like

For getting the size of the file consistently, I would recommend using stat. Using something like ls -l | cut -f 5 -d " " is very prone to error. Group names can have spaces in them (especially if LDAP mapped) and the number of spaces might confuse the cut

I hope that this helps,
Robin

1 Like