2011-11-12 44 views
0

我有從系統日誌中捕獲的格式化URL的實時列表,並將其輸出到不同的日誌文件。Geektool和尾部跟蹤

tail -F /var/log/system.log | grep --line-buffered「query =」| sed -le「s /.* query = //」| SED -le 「S/\」 // G」 | sed的-le 「S /.$/ /」 >> /tmp/urls.log

如何啓動這個自動樣的cronjob,但只運行一次。在每次登錄

原始日誌文件是這樣的:!

X YY ZZZ查詢= 「www.yahoo.com」

掙扎了一個晚上在此感謝

+0

忽略標題說「GeekTool」。 –

+0

爲什麼要在登錄時運行它? –

回答

0

使用LaunchAgent應該可以工作。用下面創建一個文件的.plist:

<?xml version="1.0" encoding="UTF-8"?> 
http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<dict> 
     <key>label</key> 
     <string>name you want to give it</string> 

     <key>ProgramArguments</key> 
      <array> 
      <string>/bin/bash</string> 
      <string>/path/to/your/script.sh</string> 
      </array>  


     <key>RunAtLoad</key> 
     <true/> 

     <key>OnDemand</key> 
     <false/> 

     <key>KeepAlive</key> 
     <false/> 
</dict> 
</plist> 

保存此文件到~/Library/LaunchAgents。然後,您需要通過執行launchctl load -wF /path/to/launch.plist來加載清理程序。爲了確保它正確加載,請檢查它是否在這裏輸出launchctl list

欲瞭解更多信息,你可以看看Apple Developer 1Apple Developer 2

+0

我看起來像是正確的解決方案。我今天會嘗試這個。謝謝! –