Script for count files and send mails

Hi.

I'm new on this forum and I need if possible someone to help me with one script.

The script should act like this:

  • should be run by crontab and have next parameters:
    script_name $par1 $par2 $par3 $par4

where script will search in dir $par1 for files with mask $par2 and if number of this files is greater than $par3 will send email to $par4.

Till now I manage to get the file number with this command:

ls -l *sorts 2>/dev/null | awk '/^-/{c++}END{ print c }'

but this will just display the number and don;t help me

May someone help me with this?
Thank you in advance!!!

How about?

if [ $( ls -l *sorts 2>/dev/null | awk '/^-/{c++}END{ print c }' ) -gt $par3 ]
then
      echo "Number of files is greater than $par3" | mailx -s "Subject" $par4
fi

Thank you very much. With some little adjustments was working perfect!
Thank you again & have a nice day! :b: