logger命令
logger是一个shell命令接口,可以通过该接口使用Syslog的系统日志模块,还可以从命令行直接向系统日志文件()写入一行信息。
-i 在记录上显示pid进程号
-t 给日志记录打标签
1、直接向系统日志写入信息
[root@localhost] /etc$ logger system reboot [root@localhost] /etc$ tail -n 1 /var/log/messages Mar 2 17:55:26 localhost root: system reboot
2、指定标签和pid
[root@localhost] /etc$ ping 172.16.2.116 -c 4|logger -it logger_test [root@localhost] /etc$ tail -f /var/log/messages Mar 2 17:52:24 localhost logger_test[25778]: rtt min/avg/max/mdev = 0.215/0.283/0.309/0.043 ms Mar 2 17:53:09 localhost logger_test[25781]: PING 172.16.2.116 (172.16.2.116) 56(84) bytes of data. Mar 2 17:53:09 localhost logger_test[25781]: 64 bytes from 172.16.2.116: icmp_seq=1 ttl=64 time=0.537 ms Mar 2 17:53:10 localhost logger_test[25781]: 64 bytes from 172.16.2.116: icmp_seq=2 ttl=64 time=0.374 ms Mar 2 17:53:11 localhost logger_test[25781]: 64 bytes from 172.16.2.116: icmp_seq=3 ttl=64 time=0.176 ms Mar 2 17:53:12 localhost logger_test[25781]: 64 bytes from 172.16.2.116: icmp_seq=4 ttl=64 time=0.403 ms Mar 2 17:53:12 localhost logger_test[25781]: Mar 2 17:53:12 localhost logger_test[25781]: --- 172.16.2.116 ping statistics --- Mar 2 17:53:12 localhost logger_test[25781]: 4 packets transmitted, 4 received, 0% packet loss, time 3002ms Mar 2 17:53:12 localhost logger_test[25781]: rtt min/avg/max/mdev = 0.176/0.372/0.537/0.130 ms