CentOS 7.7.How to use Shell script to monitor the number of logged-in users and configure QQ Mail to send email alarms
CentOS 7.7.How to use the Shell script to monitor the number of logged-in users and configure QQ Mail to send email alarms. In view of this question, this article introduces in detail the corresponding analysis and answers, hoping to help more partners who want to solve this problem to find a more simple and easy way.
First, configure QQ Mail to send mail:
# yum-y install mailx
# cp / etc/mail.rc {, .bak}
# vim / etc/mail.rc, with the following code added at the end:
Set from=834143808@qq.com
Set smtp=smtp.qq.com
Set smtp-auth-user=834143808@qq.com
Set smtp-auth-password=QQ mailbox authorization code
Set smtp-auth=login
# echo "Hello World" | mail-s "test" 834143808@qq.com
Second, write a Shell script to monitor the number of logged-in users:
Goal: the number of logged-in users in the system is more than 3, and email alarm is realized.
# mkdir-pv / scripts
# vim / scripts/check_users.sh
#! / bin/bash
Users= `who | wc-l`
If [$users-gt 3]; then
Echo "the number of current system login users is $users" | mail-s "system login users" 834143808@qq.com
Fi
# chmod + x / scripts/check_users.sh
III. Prepare a mission plan:
# crontab-e
* / 5 * / scripts/check_users.sh & > / dev/null
Fourth, open more connection windows, simulate multi-user login, and test email alarms:
This is the answer to the question about how CentOS 7.7 uses the Shell script to monitor the number of logged-in users and configure QQ Mail to send email alarms. I hope the above content can be of some help to all of you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.