Need a help on the below shell script

I have changed the code to zip and sent to the users as exhange has a maximum send/ receive limit of 20 MB

REPORT_FILE=$(ls $new_mdatfile_cat.csv)
REPORT_FILE_SIZE=$(ls -ltr $new_mdatfile_cat.csv | awk '{print $5}')
if [[ -f $REPORT_FILE ]]; then
# Check the file size, if its greater than 20 MB then zip the file,else dont
if [[ $REPORT_FILE_SIZE > 20971520 ]];then
ZIP_FILE_NAME=$(ls $new_mdatfile_cat.csv | awk -F '.' '{print $1}')
zip $ZIP_FILE_NAME.zip $new_mdatfile_cat.csv || error_func "The Report file cannot be zipped"
#Send the zipped file to the NOTIFY
echo " Report for:
Histroy category: $old_mdatfile_cat, current category: $new_mdatfile_cat
" | mimemail -s "Zipped Report" -t -b $ZIP_FILE_NAME.zip
 
move_to_history_area_func $new_mdatfile_cat.$WEEK || \
error_func "Failed to move current to history area: $new_mdatfile_cat.$WEEK"
else
echo "Report for:
Histroy category: $old_mdatfile_cat, current category: $new_mdatfile_cat
" | mimemail -s " Report" -t -a $QC_REPORT_FILE
 
move_to_history_area_func $new_mdatfile_cat.$WEEK || \
error_func "Failed to move current to history area: $new_mdatfile_cat.$WEEK"
fi
else
error_func "Error while creating report in perl script"
fi
 
 
move_to_history_area_func()
{
tar_file=${1}.tar
for ifile in ${FILES}
do
[[ -f $ifile ]] || return 1 # return error if input file is missing
done
tar -cvf $tar_file ${FILES} || return 1
[[ -f $HISTORY_AREA/$tar_file ]] && rm -f $HISTORY_AREA/$tar_file
mv $tar_file $HISTORY_AREA/$tar_file || return 1
}

I could see the files are moved to the destination correctly. eventhough error function occurs stating that "Failed to move current infomart to history area".

Please let me know what I did wrong,

Can you please run your script with -x option and see what actually is happening and post here if there are any anomallies?

Thanks for using code tags in your first post!

What's the value of ${FILES} in move_to_history_area_func() ?

Some comments:
Good indentation improves readability and comprehensibility for everyone including yourself
Typing in (nearly) identical code twice is cumbersome and error prone. Identify the differences, handle them in the if ... then ... else ... fi construct, and then go on with one version of the residual code.

+ move_to_history_area_func Q35097C.W1834
+ tar_file=Q35097C.W1834.tar
+ [[ -f Q35097C.CNT ]]
+ [[ -f Q35097C.DIC ]]
+ [[ -f Q35097C.DIM ]]
+ [[ -f Q35097C.FOR ]]
+ [[ -f Q35097C.HIE ]]
+ [[ -f Q35097C.LVL ]]
+ [[ -f Q35097C.MEA ]]
+ [[ -f Q35097C.MET ]]
+ [[ -f Q35097C.VAR ]]
+ [[ -f Q35097C.001 ]]
+ tar -cvf Q35097C.W1834.tar Q35097C.CNT Q35097C.DIC Q35097C.DIM Q35097C.FOR Q35097C.HIE Q35097C.LVL Q35097C.MEA Q35097C.MET Q35097C.VAR Q35097C.001
a Q35097C.CNT 5 blocks
a Q35097C.DIC 1167 blocks
a Q35097C.DIM 4 blocks
a Q35097C.FOR 19 blocks
a Q35097C.HIE 1 blocks
a Q35097C.LVL 5 blocks
a Q35097C.MEA 2 blocks
a Q35097C.MET 5 blocks
a Q35097C.VAR 1 blocks
a Q35097C.001 7272 blocks
+ [[ -f /ss/files/QC/Q35097C.W1834.tar ]]
+ mv Q35097C.W1834.tar /ss/files/QCRepository/Q35097C.W1834.tar
+ error_func Failed to move current infomart to history area: Q35097C.W1834
+ [[ -n Failed to move current to history area: Q35097C.W1834 ]]
+ echo ERROR: Failed to move current to history area: Q35097C.W1834
+ mailx -s QC report error: /ss/files/qc.Q35097/.qc.Q35097 
+ exit 1
ERROR: file_qc.sh Q35097C.CNT Q35097C.DIC Q35097C.DIM Q35097C.FOR Q35097C.HIE Q35097C.LVL Q35097C.MEA Q35097C.MET Q35097C.VAR Q35097C.001 failed

try to move test files with manuel and what about of result ?
if you want to a solution you must paste the full script code and because of there is no error handlers in your code and move function is not correct position

thanks

What puzzles me is

  • No error msg between these two commands (yet move_to_history_area_func() must return 1):
+ mv Q35097C.W1834.tar /ss/files/QCRepository/Q35097C.W1834.tar
+ error_func Failed to move current infomart to history area: Q35097C.W1834
  • The "infomart" in above call to error_func is NOT mentioned in the script

Try to

  • echo something at the end of move_to_history_area_func()
  • put the error _func call into the same line as the move... call, i.e. no continuation "\" in both places.
  • show us the location of the "infomart" word.

Incomplete code only allows for a guess response.

Here's an observation:

Posted bit:

+ [[ -f /ss/files/QC/Q35097C.W1834.tar ]]
+ mv Q35097C.W1834.tar /ss/files/QCRepository/Q35097C.W1834.tar

You are checking the existence of a tar in the following path /ss/files/QC/Q35097C.W1834.tar
But then, you ONLY use a relative path with move.
Shouldn't be:

mv /ss/files/QC/Q35097C.W1834.tar /ss/files/QCRepository/Q35097C.W1834.tar

could you please anyone check whether if loops is correct.

# Check the file size, if its greater than 20 MB then zip the file,else dont
if [[ $REPORT_FILE_SIZE > 20971520 ]];then
ZIP_FILE_NAME=$(ls $new_mdatfile_cat.csv | awk -F '.' '{print $1}')
zip $ZIP_FILE_NAME.zip $new_mdatfile_cat.csv || error_func "The Report file cannot be zipped"
#Send the zipped file to the NOTIFY
echo " Report for:
Histroy category: $old_mdatfile_cat, current category: $new_mdatfile_cat
" | mimemail -s "Zipped Report" -t -b $ZIP_FILE_NAME.zip
 
move_to_history_area_func $new_mdatfile_cat.$WEEK || \
error_func "Failed to move current to history area: $new_mdatfile_cat.$WEEK"
else
echo "Report for:
Histroy category: $old_mdatfile_cat, current category: $new_mdatfile_cat
" | mimemail -s " Report" -t -a $QC_REPORT_FILE

O/p:

QC_REPORT_FILE_SIZE=2115266
+ [[ -f Q35088C.csv ]]
+ [[ 2115266 > 20971520 ]]
+ + ls Q35088C.csv
+ awk -F . {print $1}
ZIP_FILE_NAME=Q35088C

Becauss I could see its getting zipped eventhough it is less than 20 mb

Please use code tags as required by forum rules!

man bash :

while executing this
Case 1 :

if [[ 2115266 > 20971520 ]];then
echo "greaterr...!"
else
echo "lesser:-("
fi

result : greate.

 
 
 
 
Case : removed the space
if [[2115266 > 20971520]];then
echo "greater...!"
else
echo "lesser :-("
fi

Result : Lesser
Let me know how to delete the space in the if loop

I'm pretty sure "lesser :-(" is not the only output you see. Unless stderr was redirected, there should also be sth like [[2115266: command not found
[[ and ]] need the spaces around them; for integer comparison use -gt