Tuesday, May 22, 2012

logger and syslog - How to log to custom log file?

[root@client ~]#cat sample_log.sh
#!/bin/bash
# Script to log to custom log file

logger -p local5.info "hello im here..."

[root@client ~]# more /etc/logrotate.d/myapp
/var/log/myapp.log {
    daily
    missingok
    notifempty
    rotate 10
    compress
}

Append the below in to syslog.conf file

[root@client ~]# less /etc/syslog.conf
# Save app logs to myapp.log
local5.*                                        /var/log/myapp.log

[root@client ~]# /etc/init.d/syslog restart
[root@client ~]# ls -ltr /var/log/myapp.log
-rw------- 1 root root 0 May 23 09:13 /var/log/myapp.log

Now,

[root@client ~]# sh log_err.sh

[root@client ~]# less /var/log/myapp.log
May 23 09:13:48 client root: hello im here...


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

Facility defines the source of the log entries, what kind of services that send this logs. Lets look at Facility info that extracted from RFC 3164, each facility was been assign a numeric code.

    Numerical       Facility
          Code
           0             kernel messages
           1             user-level messages
           2             mail system
           3             system daemons
           4             security/authorization messages
           5             messages generated internally by syslogd
           6             line printer subsystem
           7             network news subsystem
           8             UUCP subsystem
           9             clock daemon
          10             security/authorization messages
          11             FTP daemon
          12             NTP subsystem
          13             log audit
          14             log alert
          15             clock daemon
          16             local use 0  (local0)
          17             local use 1  (local1)
          18             local use 2  (local2)
          19             local use 3  (local3)
          20             local use 4  (local4)
          21             local use 5  (local5)
          22             local use 6  (local6)
          23             local use 7  (local7)
 
Severity is the log levels that defines how critical of the log entries, from 0 – 7, 0 indicates the most critical and 7 is for debugging purpose.

    Numerical         Severity
          Code

           0       Emergency: system is unusable
           1       Alert: action must be taken immediately
           2       Critical: critical conditions
           3       Error: error conditions
           4       Warning: warning conditions
           5       Notice: normal but significant condition
           6       Informational: informational messages
           7       Debug: debug-level messages

rsync with delete option and different ssh port

How to rsync e.g PIPELINE dir from Source to Destination? #rsync -avzr   --delete-before  -e "ssh -p $portNumber"  /local...