views:

167

answers:

4

Hi All,

I realize that it can depend on certain things (and obviously how efficient the code is written); but, in general, what is the most 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 cron jobs?

NOTE: Huh ... down-voted? I wonder why ...

Thanks,

Steve

+2  A: 

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.

DVK
I don't know why Logo would be disqualified by reason #1. Berkeley Logo (the major implementation) even uses `#!` as the comment marker so you can make shebang scripts with it.
Ken
My bad. LOGO sure changed in the last 20+ years!
DVK
To extend your point #1, I would agree that image-based languages like Smalltalk and Lisp are probably less suited to cron jobs. It's not that they can't be used for that, but it's not exactly one of their main strengths. A language like Ruby, which seems to have grown up on the Unix command line, but offers most of the advantages of Smalltalk and Lisp, would be a more natural choice.
Ken
P.S., Logo is a real language, very close to a Lisp dialect. Don't be fooled by the fact that every elementary school in the country taught only the "turtle graphics" part of it once. Java was once just lame "Java applets" on the web, too, but that doesn't make it any less of a valid language for programming servers today. :-)
Ken
@Ken - OK, I'm now thoroughly confused. Why do you consider Lisp to be "image based"? The extent of my Lisp experience/knowledge was 100% CLI. P.S. WOW! Didn't know LOGO was designed off of Lisp! (back when I was 7 or 8 and learned LOGO for 1/2 a year, I didn't know about functional programming yet)
DVK
DVK - "Image based" has nothing to do with whether you see images or use a CLI... It means that the program runs from a stored memory image of the machine/interpreter state.
Joe Koberg
A: 

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.

Andy Shellam
PHP is fine - i"ve been running multiple scripts, some called every minute, some every hour. Everything works as expected.
dusoft
I didn't say PHP wasn't good for this job - just saying that a lot of PHP scripts are heavily dependent on the webserver (reading certain values of $_SERVER or $_COOKIE for instance which won't work from the CLI.)
Andy Shellam
A: 
  • 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.

voyager
+1  A: 

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.

Joe Koberg
Don't pretty much all languages (may be outside of shell scripts?) have that capability?
DVK
DVK: Does C? Or C++?
Ken
Our C++ does generate stacktrace, coredump, and appropriate notification everytime the program dies. Just a matter of good software engineering. But the capability is there.
DVK
Here's an example: http://stacktrace.sourceforge.net/
DVK
Even on a segfault?
Joe Koberg
I have a suspicion Perl would forego stack trace as well should perl interpreter segfault
DVK
It's true. But I trust the heavily tested interpreter more than I would trust my ability to write correct code in C/C++!
Joe Koberg
Good point! Thankfully, I have a heavily tested library at my disposal (10+ years old used in production by a mid-sized-to-large-sized company :)
DVK