script which monitor and mail

Posted on 2008-11-19
Last Modified: 2013-12-27
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

i hope i comprehend properly.

Question by:rameshramph07
    LVL 40

    Expert Comment

    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?
    LVL 48

    Accepted Solution

    What format is the date on the filename?  Does it include the time?  If so, you could do something like
    while true
      file=`ls /home/ramesh/test_ramph_* 2>/dev/null`
      if [ -n "$file" ]
         cp $file /home/rajesh
         echo "file is missing" | mailx -s "File missing"
      sleep 60 # Adjust to whatever frequency you want, or use a cronjob

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap ( Version 1.2 2.      Jpcap( Version 0.6 Prerequisite: 1.      GCC …
    Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    This tutorial goes over how to archive and restore FreeBSD jails that are managed by ezjail.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now