This article is old and is being consolidated into the book.
Please refer to the corresponding chapter(s) therein.
If the chapters or sections are not completed yet, you can use this article.
Refer to the examples as they are tested against the latest code.
Schedule, Execute, E-Mail, SSH, SCPBy James Jianbo Huang October 2001 UPDATED: Jan 2003 non-printer versionAbstract
The
1. Scheduled Activities
The
Schedules can not be embedded. A program can have one schedule running at
a time. Each schedule is run by a timer called
To abort a schedule job, run The following program emulates a count-down process, where 4 one-time events are run one second apart.
This is a simple repetitive motion:
Next, we emulate a coocoo clock that every hour it plays so many "Cukoo" sound. Lines 1 through 4 gets the time for the next hour. Line 7 gets the time for this event, and its hour attribute is used for the number of "Cucoo" sound.
Scheduled jobs should run quickly, that is, they should not run longer than the scheduled periods. If they do sometimes and mess up the operation, practical synchronization mechanism should be put in place. For instance, suppose every 5 minutes the job checks the database for unprocessed order data. If it founds some, process them. Sometimes e-commerce site may take so many orders in a short period of time, that within that 5-minute period they can not be all processed. What you can do is, for instance, use a temporary database table; when start processing, set a flag there, and reset it when done; if this flag is set, other jobs will simply bypass. The crux of this solution is, use an operation that is always short than the period to enforce the synchronization. Monitor and Control
By issuing a
The job itself does nothing but keeping the execution time in a list for the
last 10 events (line 6). Its control panel server listens on port 3333. The
control panel is typically run from a browser. The title, "Changing Time", is
issued on line 8. The screen is standard above the horizontal line. If and
only if both boxes are checked will the job be stopped and closed. Anything
user type in to the edit box is sent to the server and becomes the content of
Review Questions
2. Sending E-Mails
You can send e-mails directly from JudoScript. To use the e-mail feature, you
need to have the The server may include a port number, separated by a colon. Once connected, you can easily send one, two, fitfy or a million e-mails from a simple JudoScript script; spamming is never easier. Well, if one does want to spam, there are zillions of ways anyway.mail::connect( server [ , username [ , password ] ] ); mail::disconnect(); The syntax for sending mail is: As you see, text and/or HTML messages can be sent at the same time. You can specify character sets for addresses, subject and bodies. If charset is set to mail::send , both the text and HTML bodies will use it.
A charset can have "charest=". The following two examples are equivalent:
Alternatively, you can call the system functionmail::send 'iso-2022-jp' ... mail::send 'charset=iso-2022-jp' ... setCharset() to set
the language character set for the whole language environment. The
mail::send command uses that if no charset is explicitly
specified in itself. This global character set may affect text encoding used
in other places.
Files can be attached; messages can be sent to a list of "to", "cc" and/or "bcc" recipients; within each list, recipients are separated by commas. Each clause can appear at most once. For the message bodies, the here-doc is a big convenience. Here is an example: The following example sends out trial software to newly registered users, whose information is stored in a database. For each user with status "NEW", a zip file and a "readme.txt" file are sent, and his/her status is changed to "TRIAL VERSION" in the database. This program is likely executed by a scheduled job that runs at midnight or later.mail::send from: 'syang@exotic.nat' to: 'foodback@judoscript.com, syang56@yahoo.cum' subject: 'bug report' body: [[* Hi there, JudoScript is cool. I'm doing a lot and will do a lot more with it. I think I've found a bug. I have a program, 'tvcontrol.judo'; there is a function like this: function switchTV $on { if $on { turnOnTV(); } else { turnOffTV(); } } however, when it is called with $on=3, it turns off my VCR! I believe this is a bug in JudoScript that, when the value is not 0 or 1, it emits erroneous radio shock waves that affect other appliances than the intended one. Please take a look. Thank you! Best regards, -- Steve Young *]]; db::connect 'jdbc:oracle:thin:@localhost:1521:userdb', 'onlyme', 'uggess'; db::query u: select email, lastname, solute from usertbl where status='NEW'; db::prepare: update userdb set status='TRIAL VERSION' where email=?; while u.next() { sendSoftware(u.email, u.lastname, u.solute); executeUpdate with @1 = u.email; } db::disconnect; function sendSoftware email, lname, solute { mail::send from: 'info@judoscript.com' to: email subject: 'The software. Thank you!' attach: 'readme.txt, software.zip' body: [[* Dear (* solute *) (* lname *), Thank you very much for your interest in this software. Attached is a zip file for the software and a readme text file. Follow the instructions therein for installation and using. Enjoy! Please visit www.judoscript.com for the latest news and information. Thank you! Sincerely, JudoScript *]] htmlBody: [[* <html><body> <p>Dear (* solute *) (* lname *), <p>Thank you very much for your interest in <i>this software</i>. Attached is a <u>zip file</u> for the software and a <u>readme text</u> file. Follow the instructions therein for installation and using. Enjoy! <p>Please visit <a href=www.judoscript.com>www.judoscript.com</a> for the latest news and information. Thank you! <p>Sincerely, <p>JudoScript </body></html> *]] ; } Review Questions
3. SSH and SCP
The SSH and SCP features uses ISNetworks' distribution of MindTerm package, a GPL'ed open-source pure Java SSH/SCP bundle. It is a GUI program that you can use daily; its SCP screen looks like a FTP GUI client. Very handy! Download it from ISNetworks. Make sure the version is "version 1.2.1 SCP release 3" or up. Unpack and put the class jar file into your classpath, and run If it is the first time use, it prompts you for host, user and password, and generates necessary keys automatically. You should run it to establish such environment before using JudoScript's SSH/SCP features. By the way, the nice SCP screen is available on its "File" menu, not so obvious to the first-time users.%java mindbright.application.MindTerm Once the jar file is in the classpath and you have set up the environment, please refer to the language spec for how to use. It is rather straightforward.
4. Summary
Running scheduled jobs is an important application of scripting languages.
The Scheduled jobs typically check database or some files for changes and respond by processing the data, running other applications, handling files and archives and sending results either via remote calls to systems or e-mails to humans. JudoScript has flexible JDBC scripting, running executables, invoking Java programs and sending e-mails. So practically you rarelly have to leave JudoScript.
The
E-mails can be sent directly via the
5. Code Listings
|