Monday, July 10, 2006

Linux: Cron

Cron is the Linux equivalent of Window's Task Scheduler.

Jobs are executed from /etc/crontab

1. Create a PHP script file.

2. Edit the crontab

# crontab –e

This is the file syntax:

minutes hours day_of_month month day_of_week command

where:

minutes: 0-59
hours: 0-23
day_of_month: 1-31
month: 1-12
weekday: 0-6
command: Any shell command or web document

Wildcard: * (Allow any value)

I will use wget because PHP files need to be parsed by Apache, we need to execute it via wget command using the URL to the page. To check if your box has wget:

# wget --help

To run the script every Wednesday morning at 9:30 AM, the cronjob file will contain the following in single line:

30 9 * * 3 wget http://www.domain.com/file.php

Save the file and add to crontab

# crontab samplecronjob

PHP: Half-byte Katakana conversion (Single-byte, Hankaku, 半角カタカナ)

mb_convert_kana() is not working for me so I found a neat php code that can convert Hankaku to Zenkaku katakana and vice versa. Also has character set conversion. It's called JCode. It's free without warranty. I've only tested jcode-LE for now.

This is the link for the one with UTF-8:
http://www.spencernetwork.org/jcode/

This is the light edition without UTF-8, only supports EUC-JP, Shift-JIS, ISO-2022-JP (JIS):
http://www.spencernetwork.org/jcode-LE/

Browsers: Compatibility

This will work in some browsers like IE. elementName is from form object's name.
formName.elementName

For compatibility, use form object's id
document.getElementById('elementID')

Another issue is using comments
<!-- comment -->

This is okay in MS IE but not in Mozilla Firefox. So avoid using this style of comment. Use only two hyphens/dashes.
<!------------ comment ----------->

(Thanks to Cacho for this)

Manipulating style attribute's display using javascript, use '' instead of 'block' or other values aside from 'none' to go back to it's default value. This is useful when showing/hiding object. Other common values are 'table-row' and 'inline'.
object.style.display = 'none';
object.style.display = ''; // restores default value.

IME Mode (Internationalization format) is an IE specific attribute in CSS.