APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

2003/12/13 logger

Writes a string to the system log file.

An ordinary user can run this without read or write permission on the system log file. It simply adds a date stamp, your login name, and whatever arguments you gave it:


$ logger fooey
$ tail -1 /var/log/system.log
Dec 12 08:35:03 localhost apl: fooey
 

There are more possibilities: you can specify a priority level, and that could cause your message to go to some other system log depending on the configuration of syslog:

 apl$ sudo cat /etc/syslog.conf
*.err;kern.*;auth.notice;authpriv,remoteauth,install.none;mail.crit            /dev/console
*.notice;*.info;authpriv,remoteauth,ftp,install.none;kern.debug;mail.crit      /var/log/system.log

authpriv.*;remoteauth.crit                              /var/log/secure.log

lpr.info                                                /var/log/lpr.log
mail.*                                                  /var/log/mail.log
ftp.*                                                   /var/log/ftp.log
netinfo.err                                             /var/log/netinfo.log
install.*                                               /var/log/install.log
install.*                                               @127.0.0.1:32376

*.emerg                                                 *
 apl$ logger -p lpr.info try this
 apl$ tail -1 /var/log/system.log
Dec 12 08:40:46 localhost apl: try this
 apl$ tail -1 /var/log/lpr.log   
Dec 12 08:40:46 localhost apl: try this
 

See also Log Level


Got something to add? Send me email.





(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> logger writes a string to the system log file.




Increase ad revenue 50-250% with Ezoic


More Articles by

Find me on Google+

© Tony Lawrence



And of course you can use PERL to log events to your syslog, with Sys::Syslog - which can be done like this:

-----BEGIN script
#!/usr/bin/perl -w
# Script to log HOT to /var/log/messages if the temp
# id higher than the varibale set below in $temp
#
# Requires: Device-Serial per module.
# Requires: Sys::Syslog

use Device::SerialPort 0.05;
use Sys::Syslog qw(:DEFAULT setlogsock);
use strict;

my $Temptrax = "/dev/ttyE4";
my $pass;
my $return;
my $new;
my $HOT;
my $time;
my $bldg;
my $room;


$time = localtime;


################################
# BEGIN Variable Configuration #
################################

# $temp is the max or min temp before we start YELLING!
my $temp = "76";

# $bldg is the building where the Temptrax is located
$bldg = "164 Fredette St.";

# $room is the Room in which the Temptrax is located
$room = "Computer Room";

##############################
# END Variable Configuration #
##############################

# Constructor & Basic Values

my $ob = Device::SerialPort->new ($Temptrax) || die "Can't open $Temptrax:$!";

$ob->baudrate (9600) || die "fail setting baudrate";
$ob->parity ("none") || die "fail setting parity";
$ob->databits (8) || die "fail setting databits";
$ob->stopbits (1) || die "fail setting stopbits";
$ob->handshake ("none") || die "fail setting handshake";
$ob->dtr_active (1) || die "fail setting dtr_active";

$ob->write_settings || die "no settings";

sleep 1;

#send a dummy character to the TempTrax device to "wake it up"
#The temperature will be returned

$pass = $ob->write("a") or die ("Could not write to Temptrax: $!");

sleep 1;

if (($return = $ob->input) ne "") {
$ob->write($return);
$new = substr($return, -15) = "";
if ($return > $temp) {

# use perl syslog facility
my $count = 0;
my $host = "localhost";
setlogsock("unix");
openlog(basename($0), "pid", "local3");
syslog("warning", "COMPUTER ROOM: ** HOT **: $return");
closelog();

}
}
---------END script

I use that program from cron to query a temperature probe that is located in our computer room. I then use swatch to look for the word HOT and page me. The temperature probe hardware can be found here: http://www.temptrax.com I use the RS-232 version.

- Bruce Garlock

---------------------

Aso, don't forget that most UNIX systems listen on UDP port 514 and write whatever shows up there into syslog. I often use this feature to monitor HP JetDirect print servers when something is acting up.

--BigDumbDinosaur



Kerio Samepage


Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us





Computer Science is embarrassed by the computer. (Alan Perlis)

I had a life once. Now I have a computer. (unknown)







This post tagged: