Лучшие практики для поддержки cronjobs и сценариев оболочки?

Я унаследовал обширный crontab, который мне нужно поддерживать и обновить. У меня нет большого опыта в этом или в написании сценариев на bash (я думаю, что я хорошо разбираюсь в основах), и я хочу делать хорошую работу.

Я унаследовал обширный crontab, который мне нужно поддерживать и обновлять. У меня нет большого опыта в этом или в написании сценариев bash (я думаю, что я достаточно хорошо разбираюсь в основах), и я хочу делать хорошую работу.

Я унаследовал обширный crontab, который мне нужно поддерживать и обновлять. У меня нет большого опыта в этом или в написании сценариев bash (я думаю, что я достаточно хорошо разбираюсь в основах), и я хочу делать хорошую работу. Short request: Any guidelines for 'refactoring' a messy crontab and set of bash scripts

Long request: I've run into a number of issues, but are so many people using cron files etc that I feel like I must be missing some large repository of information, best practices and tools - or is this just a stylistic difference for this kind of programming? (My bias: why do something manually if I can use a tool to do it faster, consistently and well?).

Examples of issues so far:

  1. Due to an external event, the crontab didn't run for a couple of days. Along with someone else, we manually went through the list, trying to figure out what didn't run, what we needed to rerun, and what scripts we needed to edit and run with earlier dates etc. What I can't find:

    • There are plenty of (slightly pointless) 'cron generators' online. Where are the reverse? Something I can feed in a long crontab, two dates, and have it output which processes should have run when, or just how many times total? This seems within my meager scripting capabilities, so shouldn't it exist already? ;)
    • Alternatively, if I ever have to do that again, is there some way of calling a bashscript so that any instances of date() are pre-set to an earlier time, rather than changing every date call within the script? (e.g. for all the missed reports and billing invoices)
  2. It turns out a particular report hadn't been running for two years. It was just requested again, and lo, there it was in the crontab! The bash script just had broken path references to the relevant files. What I can't find: some kind of path checker for bash files? Like a website link checker. Yes I'll be going through these all manually eventually, but it'd show up some at least some of the problem areas.

  3. It sounds like some times, there has either been too long or short a gap between dependent processes, so updates have happened after the first has been run, or the first hasn't finished running before the second has been called. I've seen a few possible options for this (eg anacron runs in sequential order), but what would you recommend?

  4. There are also a large number of essentially meaningless emails generated from the crontab (scripts throwing errors but running 'correctly', failing mostly silently, or just printing everystep of non-essential scripts). I'll be manually going through scripts and trying to get them to provide more useful data, or 'succeed quietly', but y'know - any guidelines?

If my understanding or layout of the issue is confused, then I apologize, but hey - you see my problem then! I need to go from newbie, to knowing what to do to get this right, and not screw up a touchy system further. Thanks!

13
задан Azazo 13 April 2011 в 10:55
поделиться