LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-18-2011, 02:07 PM   #1
veeruk101
Member
 
Registered: Mar 2005
Distribution: Ubuntu 12.04 LTS
Posts: 249

Rep: Reputation: 16
Put each daily cron task in a separate script or put them all in one script?


I need to run some tasks in anacron (not regular cron), and apparently the way it works is I put these scripts in /etc/cron.daily and anacron will take care of the rest. I have two options - put every task in one big bash script, or put each task in its own script. In general terms, what things should I be considering when making the decision of which way to go about it?

One thing I see that might make it better to go with one big script is I can ensure some tasks are run before others. Or will the scripts in /etc/cron.daily run in alphabetical order? In /etc/anacrontab, the following is included, and I can't tell whether run-parts will execute them in alphabetical order, and if so whether this would be a nuance of this particular system or whether that behavior is standard:

Code:
1	  5	cron.daily		nice run-parts /etc/cron.daily
Apart from that consideration, what other things should I be looking at in terms of how to organize all my cron tasks? How do you do it in your systems? Any best practices, tips, or things to think about you could suggest would be great.
 
Old 10-18-2011, 03:43 PM   #2
xjonquilx
Member
 
Registered: Jul 2011
Location: FL, USA
Distribution: Linux Mint 13
Posts: 169

Rep: Reputation: Disabled
Well, there's several ways you could go about this.

You could put them in separate files so you only have to run the ones you need at the moment.

You could put them in one file so they all run at once.

And one option I didn't see considered: You could put them in one file with a text menu so you can select which ones you want to run.

Any of these methods will work, it just depends on what you want to do. And you don't seem very certain that you know what you want to do so that would be your first step.

Sorry I can't help more than this. I'm not a system administrator.
 
Old 10-18-2011, 03:59 PM   #3
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
Even though anacron behaves differently than does cron, the idea is more-or-less the same -- if you need to run some group of tasks where subsequent tasks depend upon some prior task being completed, you want to place those task in sequence in one shell program (script). Things that do not depend upon some prior task completing can stand alone.

Something to be aware of in any case, ancron or cron, is that the shell that cron jobs run in by default is extremely limited. If you are going to be executing a program found in /usr/local/bin, for example, it frequently is necessary to add that directory to the PATH environment as well as any libraries found in /usr/local/lib to the LD_LIBRARY_PATH environment variable; e.g., at the top of your shell program
Code:
export PATH=${PATH}:/usr/local/bin
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib
You would do the same for any other directories containing executables you would be using in the job.

One does wonder, though, why you would be using anacon rather than just plain old cron? It appears that the only real benefit is that a cron job will be run by anacron if the system has been shut down for some reason when the system is restarted. If you don't expect (or experience) a lot of powered-off time...

Anyway.

Hope this helps some.
 
Old 10-19-2011, 06:32 AM   #4
veeruk101
Member
 
Registered: Mar 2005
Distribution: Ubuntu 12.04 LTS
Posts: 249

Original Poster
Rep: Reputation: 16
I'm using anacron because it's a laptop not a server that can be expected to remain on at all times. If I use cron instead of anacron, most of my cron runs won't actually run.

So are the scripts in the cron.daily directories (as executed by run-parts) always executed in alphabetical order and, if so, is this behaviour standard and can be relied upon?
 
Old 10-19-2011, 07:10 AM   #5
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
Quote:
Originally Posted by veeruk101 View Post
I'm using anacron because it's a laptop not a server that can be expected to remain on at all times. If I use cron instead of anacron, most of my cron runs won't actually run.
Well, that's what the purpose of it is, so sounds like you've got the right tool (I wasn't being critical, just curios!).
Quote:
So are the scripts in the cron.daily directories (as executed by run-parts) always executed in alphabetical order and, if so, is this behaviour standard and can be relied upon?
That I don't know (but it's quite possible if it uses some form of ls to get the file names). Best bet? Make up a few that just just echo something like "this is a," "this is b" and so on and see what happens (ought to be a log, eh?).

Last edited by tronayne; 10-19-2011 at 07:11 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] /etc/cron.daily/tmpwatch script Soji Antony Linux - Newbie 4 04-15-2011 06:05 AM
cron - how to give priority to a task running in cron.daily? MeeLee Linux - Newbie 3 11-09-2010 08:41 AM
script not executed by cron.daily hopefull Linux - Newbie 6 01-17-2009 09:54 AM
Script not being run in cron.daily hazmatt20 Linux - General 10 10-12-2008 08:24 PM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration