Saturday, November 27, 2010

Linux operating system log management common skills introduction

1. use the Shell to the Syslog log file write applications using the Syslog Protocol to send information to the Linux system log files (located in/var/log directory).

Sysklogd provides two system tools: one is a system logging and the other kernel information capture. Usually most programs use C language or Syslog application or library to send Syslog messages. The following describes how to use the Syslog log file sShell written information: (1)-use Logger command Logger command is a Shell command (interface). You can use this interface using Syslog-syslog module you can also directly from the command line to the system log file is written to the row information. For example, record hard drive upgrade after system restart information: $ loggerSystemrebootedforharddiskupgrade then you can view the/var/log/message file: # tail-f/var/log/message output: Jan2620: 53 31dell6400logger: Systemrebootedforharddiskupgrade you can also use script programs to use the Logger command. See the example below: #!/bin/bas HDBS = "db1db2db3db4" BAK = "/sout/email" [!-d $ BAK] & & mkdir-p $ BAK | |:/bin/rm $ BAK/* NOW = $ (date + "% d-% m-% Y") ATTCH = "/sout/backup. $ NOW.tgz [-f $ ATTCH] & &/bin/rm $ ATTCH | |: MTO =" & nbspyou@yourdomain.com "fordbin $ DBS do FILE =" $ BAK/$ db. $ NOW-$ (date + "% T") .gz "mysqldump-uadmin-p'password ' $ db | gzip-9 > $ FILE done tar-jcvf $ ATTCH $ DB $ BAK mutt-s" NOW "-a $ $ MTO ATTCH <    dbs$(date)  eo   ["$?"!> = "0"] & & $ 0-MySQLBackupfailed "logger" | |: If MySQL database backup failed, above the last line of code will write a message to/var/log/message file. (2). the other usage if you need to record/var/log/myapp.log information in the file, you can use: $ logger-f/var/log/myapp.log to send a message to the screen (standard error), such as the system log: $ logger-s "Harddiskfull"

No comments:

Post a Comment