• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 295
  • Last Modified:

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

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?
0
WH_Tech
Asked:
WH_Tech
2 Solutions
 
TintinCommented:
Something like

0 0 * * * [ -f /some/file ] && additional code
0
 
woolmilkporcCommented:
Yep.

* * * * * [ -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.

wmp
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.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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