Work the Shell - Compact Code and Cron Contraptions
Speaking of which, the way that you get to the data file that defines which jobs you want run when from the crontab facility is the crontab command. Log in as the desired user (probably root in this case), then type:
You'll now be editing a file with comments (lines starting with #) and lines composed of five space-separated values followed by an sh command, like this:
* * * * * /home/taylor/every-minute.sh
This is rather brutal on the system. It invokes this script every single minute of every day—probably overkill for just about any process, but it illustrates the basic format of crontab entries.
The fields are, in order, minute, hour, day of month, month and day of year. To have our job run every hour, for example, we can simply set the minute field to a specific value. For example:
10 * * * * /home/taylor/every-hour.sh
Every hour, at ten minutes after the hour, the script is run. That works.
Now, to stitch it all together, the best bet is to drop the find command into a very short shell script and invoke the script with cron, rather than having the command itself in the crontab file. Why? Because it gives you lots of flexibility and makes it very easy to expand or modify the script at any time.
Put everything in this column together and you should be able to really start exploiting some of the recurring job capabilities of your Linux box. I am a big fan of cron and have many, many jobs running on a nightly basis on my servers. It's well worth learning more about, as is the find command.
Now, what were we talking about earlier?
Dave Taylor is a 26-year veteran of UNIX, creator of The Elm Mail System, and most recently author of both the best-selling Wicked Cool Shell Scripts and Teach Yourself Unix in 24 Hours, among his 16 technical books. His main Web site is at www.intuitive.com.
Dave Taylor has been hacking shell scripts for over thirty years. Really. He's the author of the popular "Wicked Cool Shell Scripts" and can be found on Twitter as @DaveTaylor and more generally at www.DaveTaylorOnline.com.
- Readers' Choice Awards 2013
- Advanced Hard Drive Caching Techniques
- Linux Kernel News - November 2013
- December 2013 Issue of Linux Journal: Readers' Choice
- Mars Needs Women
- Sublime Text: One Editor to Rule Them All?
- Raspberry Pi: the Perfect Home Server
- RSS Feeds
- Web Administration Scripts
- New Products
- animal pajamas
2 hours 8 min ago
- thanks for you post.
2 hours 15 min ago
- thanks for share, great
19 hours 29 min ago
- There are factors which are
1 day 29 min ago
- Gnome 3 ?
1 day 1 hour ago
- Reply to comment | Linux Journal
1 day 5 hours ago
- "Redis RethinkDB 4.5%" on Best NoSQL Databases
1 day 15 hours ago
- on the ground
1 day 21 hours ago
- I was able to read the whole
1 day 23 hours ago
- since i have read the title i
2 days 2 hours ago