开发者

Suitable language for cron Jobs?

开发者 https://www.devze.com 2022-12-21 13:32 出处:网络
I realize that it can depend on certain things (and obviously how efficient the code is written); but, in general, what is the most suitable and perhaps efficient language to use in writing cron jobs?

I realize that it can depend on certain things (and obviously how efficient the code is written); but, in general, what is the most suitable and perhaps efficient language to use in writing cron jobs?

Does this simply come down to a question of what is the most efficient language period, or can the specificity of cron jobs determine one programming language over the other?

Also, does MySQL database operations affect the programming language of choice for开发者_如何学JAVA cron jobs?


Any language (in case of MySQL, any language with mySQL libraries) can be used as long as it has:

  1. Command line interface. Not sure which languages disualify - apparently even LOGO has CLI capable implementations now, though what use is LOGO in background program is somewhat beyond me :)

  2. Resulting code runs on whatever system your cron daemon is on (most usually, a Unix server, but I assume there are cron ports to Windows etc...)

Any other considerations have nothing to do with cron jobs.

Efficiency wise, it depends entirely on what the work done by the job is (but again, not really related to cron-ifying the job).

With some extreme performance-intensive exceptions, choose the best language you can develop in (based on your familiarity with it and the availability of needed libraries).

For performance sensitive code, the usual choice is C++ and/or Assembly for really optimized stuff - but to be honest the whole performance discussion is completely outside the scope of your question and I'm sure has plenty of perfectly-answered question on StackOverflow elsewhere.


Since your code is running unattended at odd hours, you want a language with good error handling and reporting. Namely, it needs to print a traceback when it crashes.


Most cron jobs I've come across have been in bash (or the scripting language of the system's shell.) However if performance is critical, I write a C++ application to do what I want (although there really aren't many times when a bash script hasn't been sufficient.)

I've also seen some PHP scripts called from a cronjob - we've got a third-party supplied PHP application which has an associated cron.php run every hour.

Pretty much anything that can run from a shell prompt can be run from cron, so you can access the MySQL command-line tools from within bash as if you were doing it manually at the shell. If a PHP application/script is written so it doesn't depend on the webserver (apps based on the MVC model are a good candidate) it can also be called using php -f <php_script.php> from a cron job.


  • Bash: ubiquitous, simple, excels at file handling operations, might get hard to do MySQL operations.

  • Perl: ubiquitous, well known by Unix bearded sysadmins, incredibly big repository of libraries. Might be a little hard to maintain of you are not careful with the style of your code.

  • Python: ubiquitous but might be older versions (anything Python 2.3+ is good and you are not likely to find older in the wild), great libraries, ease of use, maintainable code because of stricter syntax than perl. Might be a bit harder to find people that already knows it, but it shouldn't be that hard to get up to speed.

Both Perl and Python have extensive time tested MySQL bindings and come standard, just like bash, in almost all Unix derived OSes out there.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号