script which monitor and mail

Hi All,

I have to create a script which will monitor folder /home/ramesh every minutes and it will check for file name pattern test_ramph_date and if the file has been present in that forlder then it will copy that file to folder /home/rajesh. but if there is no file with that pattern, it will send a mail to xyz@abc.com.

i hope i comprehend properly.

thanks
rameshramph07Asked:
Who is Participating?
 
TintinConnect With a Mentor Commented:
What format is the date on the filename?  Does it include the time?  If so, you could do something like
#!/bin/sh
while true
do
  file=`ls /home/ramesh/test_ramph_* 2>/dev/null`
  if [ -n "$file" ]
  then
     cp $file /home/rajesh
  else
     echo "file is missing" | mailx -s "File missing" xyz@example.com
  fi
 
  sleep 60 # Adjust to whatever frequency you want, or use a cronjob
done

Open in new window

0
 
omarfaridCommented:
how frequent you want to run the script? who will run the script? do you want to automate the script run? can you give an example?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.