Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 238
  • Last Modified:

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
0
rameshramph07
Asked:
rameshramph07
1 Solution
 
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
 
TintinCommented:
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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now