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".
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.
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
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:
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
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