Archive for April, 2005

launchd and cron job

Saturday, April 30th, 2005

In OS X.4, one would discover that the file /etc/crontab is empty. If you try “sudo crontab -e“, you will find the default cron table for root is also empty. How does OS X.4 control these the timely maintenance jobs? I need to run a simple job to book keeping my battery usage log every 10 minutes. I know that I can still use “cron” to achieve this goal, however, I think it would be more fun to dig out how to archive this by using OS X way, launchd.

After reading several man pages for launchd, launchctl and launchd.plist, I find it is not hard to use the new launchd to run a program periodically. Basically, each line in the crontab is replaced by an XML file (property list), to describe how a program should be launched by the launchd daemon. One can refer to Apple’s /System/Library/LaunchDaemons/com.apple.periodic-daily.plist for the general structure of the property list format. You can create your own myjob.plist and put it in /Library/LaunchDaemon or ~ /Library/LaunchDaemon, then the system will load it in automatically after reboot or re-login. Actually, I am not sure if reboot or re-login is required. Nevertheless, you can also load the job manually by “launchctl load” and “launchctl start“. If you are interested in what jobs have been loaded by launchd, try “launchctl list” or “sudo launchctl list”.

I have not studied the mechanism behind launchd, but I notice that my weekly mantainace jobs do not run at the time specified by its configuration file. Dose launchd already have some sort of anacron function? If so, it will be a great news for powerbook or ibook user.

launchd seems to be a very capable daemon to replace some of those old unix based launchers. I like the XML property list file better than the old crontab format, which I never remember the meaning of different field unless I look up the man page. With a flexible XML format, it is quite likely to have a nice gui program to manage all launchd jobs.

General Background about launchd

The First Camping Trip in 2005

Saturday, April 9th, 2005

今年第一次露營的營地是在 Marin County 的一個靠近 Point Reyes National Seashore 的一個小鎮 Olema。本來打算星期五晚上出發的,但是因為天候不佳,所以延到星期六的早上出發。Olema 在 San Francisco 的北邊,到那最佳的景觀路線自然是經過金門大橋。我們在金門大橋的北邊的景觀點稍作停留,欣賞 Gold Gate 的壯麗的景色(1,2,3)後,便經加州的一號公路,至營地紮營。

營地因為前日下雨的關係,到處是積水的泥坑,還好搭帳篷的地方並不算太濕。約莫下午兩點左右,營地已經整理好,Joy 和我在暖暖的太陽照了一路下已有點疲憊,再加上我的食指不小心被車門挾到,痛徹心扉,乾脆先睡個午覺休息再說。睡了約一個小時,我們決定就隨性開車逛逛。延著一號公路往北,開到 Bodega Bay (google map)。

在那裡我們一時嘴饞,找了一家可以眺望海灣的餐廳點了幾個 BBQ Oyster 來吃,當作下午的點心。

從 Bodega Bay 回營地的路上,在一個雜貨店稍作停留,補充些作晚餐的菠菜,水果。回到營地後,太陽還未完全下山,就得開始起營火,做晚餐。我們的晚餐,稀飯,培根,洋蔥炒菠菜,在加上一些罐頭,很簡單,但是野地裡做飯還是別有風味。不過一開始在營地的雜貨店買的木頭有點可惡,太潮濕,起不了火,後來還是開車再去別的鎮上買了另外一捆柴,才成功的起了營火烤培根,炒菠菜,又吃了一頓別富野趣的晚餐。

營地的晚上很冷,所以大多時候只能圍在營火旁看火取暖,慢慢的等到柴燒盡了,也睏了。

第二天,我們到 Point Reyes Light House (1,2,3) 去碰運氣,看看能不能看到延著加州海岸往北遷移的灰鯨。吹風等了好一陣子,還是沒有看到任何一隻灰鯨,看來他們是不賞臉了。雖說沒等到鯨魚,但總算是一賭那長年躲在霧中的燈塔,和那浩瀚的太平洋的景色也不枉此行了。