Finding a file delivery time and sending it as an email

Hello, i have a requirement where i need to create a script which would check for a file name called XX_YYYY_ZZ in the directory inbound and as soon as the file is delivered in this directory a email needs to be sent to a user abc@yahoo.com

The plan is to put script in the core process to run it every minute to check for new files.

Thanks in advance,

Regards

RaJ

---------- Post updated at 07:16 PM ---------- Previous update was at 06:21 PM ----------

Can someone help please ?

please read forum rules.
which shell you are using?
try something:

if [ -e file ];then 
 echo "file found" | mailx -s"file found" "somename@domain.com"
fi

thanks for your reply !

I will make it a point i reply to the concerned forum from next time around. I would appreciate if one of you could help me with the script to find the time when the file was delivered rather than the availability of the time in the directory.

TIA

as you mentioned, you will run the cron in every min.
so whenever the above condition is true, you can capture the system time.

if [ -e file ];then 
 time=$(date)
 echo "file found" | mailx -s"file found" "somename@domain.com"
fi

please note it might not be the very accurate time of the file delivery.

I hope i understood you clearly.

Thanks Anchal.. i think i wasnt clear earlier. An approximate time would be enough to capture. The problem is i would like to capture the details of the file which is delivered today, because the directory could contain files with older date which isnt necessary.

So logic should be something like

1) search for filename with pattern "XXX_YYY_ZZZ" since this kind of files are delivered on a daily basis. The filename will contain some characters after this pattern.
2) Check if the file is delivered today(current day)
3) If 1 & 2 are yes then the current time should be captured along with the file name.
4) Mail to someone@domain.com

Regards

RaJ

something like:

latest_file=$(ls -1rt XXX_YYY_ZZZ* | tail -1)  ## ls -1 (one)
file_time=$(ls -lrt XXX_YYY_ZZZ* | tail -1 | awk '{print $6,$7}') ## ls -l (el)
 
today=$(date +'%b %d')
 
if [ "$file_time" = "$today" ];then
 ## mail
else
 ## no file today
fi

assuming you have all the files with the current year.

thanks.. i am getting the following errors:

./temp.sh[3] : today: not found
./temp.sh[3] : syntax error at line 5 : 'then' unexpected

can you post your code?

Sorry your code is working absolutely fine .. i think i got confused with the '1' and the 'l' .... its working now ..

how do i check this in a particular diretory.. say for example i want to look in a directory called dir_data/dir_in/..