Cron script for Linux to search for a file and then execute a function

Posted on 2010-01-04
Last Modified: 2013-12-16
I would like to create a Cron job that would search the a specific file in the Linux file system at a designated location.  If the file is found I want the script to execute a some additon code and if not just exit the script.  Is this possible?
Question by:WH_Tech
    LVL 48

    Assisted Solution

    Something like

    0 0 * * * [ -f /some/file ] && additional code
    LVL 68

    Accepted Solution


    * * * * * [ -e /your/designated/file ] && /path/to/code > /path/to/logfile 2>/path/to/errorlog

    Replace the asterisks with your desired schduling times. Use >> instead of > to append to the logfiles instead of replacing them.


    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.

    Join & Write a Comment

    Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
    Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
    Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
    This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

    746 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

    16 Experts available now in Live!

    Get 1:1 Help Now