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:


Hate these ads?



$ 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




Comments
WordsoftheDaylogger :
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



Add your comments

Enter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)

Or use any RSS reader

Delivered by FeedBurner


Views for this page
Today This Week This Month This Year  Overall
121141 990

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. We appreciate comments and article submissions.

Publishing your articles here

pavatar.jpg
More:




Unix/Linux Consultants


larryi@ccamedical.com SCO OS5, Debian Linux, RedHat Linux, MySQL, Apache, AJAX development using dXport/dL4/Unibasic, Windows Connectivity, Sharing Resouces, Automation, Shell Scripting


http://www.breakthru.com.au SCO (Openserver and Unixware), Unix, Solaris and Linux Consulting services including: Secure Networking Solutions; Linux based Firewalls; Backup Solutions; Secure Home to Office Network Setup; Phone, Remote and On-Site Support available - Satisfaction Guaranteed!


UBB Computer Services Support for Openserver, Unixware and Linux. Windows integration with Unix/Linux servers. Hardware, Backup and Networking issues. Located near Sacramento CA, we provide onsite support throughout Northern CA and Nationwide via remote access. We are a SCO Authorized Partner and a Microlite BackupEdge Certified Reseller.



Twitter
  • Nov 30 20:25
    I have 37,000 words of a 50,000 word project. I'd like to finish it this week..
  • Nov 30 20:05
    My wife made turkey sandwiches with stuffing and cranberry orange relish - I did not want to eat the last bite. Didn't want it to end!









Change Congress


Related Posts