您的位置:首页 > 运维架构 > Shell

使用Shell向syslog日志文件写入信息

2013-04-18 01:16 489 查看
使用Shell向syslog日志文件写入信息

应用程序使用syslog协议发送信息给Linux系统的日志文件(位于/var/log目录)。sysklogd提供两个系统工具:一个是系统日志记录,另一个是内核信息捕获。通常大多程序都使用C语言或者syslog应用程序或库来发送syslog消息。

1、logger命令是一个Shell命令(接口)。可以通过该接口使用syslog的系统日志模块,直接向系统日志文件写入一行信息。

2、示例

比如,记录硬盘升级后的系统重启信息:

$ logger System rebooted for hard disk upgrade

logger -f /var/log/myapp.log  //将文件中内容记录系统日志

logger -s "Hard disk full"  //把消息发送到屏幕(标准错误)

logger -i -t my_test.sh -p local3.notice " my_test.sh find some error in …"

-i  Log the process id of the logger process with each line

-s  Log the message to standard error, as well as the system log.

-f  file Log the specified file.

-t  tag  Mark every line in the log with the specified tag.

原文

[1]http://hi.baidu.com/jackbillow/item/02341e426b6952e3bdf451cf

[2]http://www.chenqing.org/2012/08/use-logger-logrotate-manage-your-logs.html

[3]对/etc/syslog.conf,/etc/logrotate.conf进行了详细的讲解
http://www.187299.com/archives/1784
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐