The program automatically collects the messages of the Day of the 12 servers, and then sends them to the mailbox
Source: Internet
Author: User
The program automatically collects the messages of the Day of the 12 servers and sends them to the mailbox-Linux Enterprise Application-Linux server application information. The following is a detailed description. Lab environment: LINUX AS4
Objective: To reduce repetitive work. View the server's messages logs every day. Each machine requires su-root and the password;
Cd/var/log; tail-300 messages; then exit and repeat it for 12 times. Today I wrote a program using ssh
It is much easier to automatically collect the messages of 12 servers on the same day and then merge them into my work mailbox.
Knowledge points used: 1: ssh verification-free, using one machine to call programs of other machines.
2: sudo, because the log format in messages is:
Apr 3 00:00:00 emaila1 sshd (pam_unix) [22744]: session opened for user root by (uid = 0) I need to find the "Apr 3" string for the logs on the day of grep. It can be truncated from the date result. I thought for a long time. There are two spaces between Apr and 3. If the two-digit date is followed by a space, the string length is 6.
Mon = "'date '";
Para = "$ {mon: 4: 6 }";
Echo "$ para ";.
Neither awk nor date can achieve the effect. Later, the string truncation method was used.
3: the root character set is LANG = zh_CN.gbk. The output log Content is: 22:43:53, December 4, April 3 CST 2008.
Not required, and it is best not to change the root of the essence, which needs to be modified in my users LANG = en_US.UTF-8.
4: How can I use my user to execute the root permission? sudo is required. Configure mongodo and set the password-free mode.
5: Content scp is merged into a machine and then merged into a file.
6: sudo echo "Messages 'date + % B _ % d'" | sudo mutt-s "Messages 'date + % B _ % d'" yang ** @ midea.com.cn-a messages. log can be sent to my mailbox.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service