Niclas Sodergard: Better Scripts #3 - use logger
When you write scripts, especially scripts that will be executed unattended by cron or a similar facility, in most cases you want some way of getting error messages. Sometimes email is the way to go, sometimes you can just redirect output to a text file. Solaris and most other *NIX operating systems are shipped with a tool to log directly to syslog, logger(1).
In the most simple form you run the command like this
$ logger this is my test message
The default syslog facility and level used by logger is user.notice and unfortunately Solaris doesn’t log that anywhere by default so the first test case is pretty much useless ;-). By changing the facility and level we can get it logged in one of the standard log files. You use the -p flag to specify that.
$ logger -p daemon.notice this is the second test message
This will now show up in /var/adm/messages.
Syslog also has a number of locally defined facilities as well, local0-local7, that you can freely use for your own application. This can be very useful for logging your own application output to a separate log file. There are a few steps we need to go through before we can accomplish this but they are all very easy.
[PlanetSolaris]