In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly tells you how to use Bash script to send new users to create email. You can check the relevant professional terms on the Internet or find some related books to supplement them. We will not dabble here. Let's go straight to the topic. I hope this article can bring you some practical help by using Bash script to send new users to create email.
A Bash script that sends mail when a new user account is created in the system
Linux has many open source monitors that can be used. But I don't think they have a way to track the process of creating new users and alert administrators when it happens.
So how can we do that?
We can write our own Bash scripts to achieve this goal. We have written many useful shell scripts in the past.
What does this script do?
This will back up / etc/passwd files twice a day (at the beginning and end of the day), which will enable you to get new user creation details on a specified date.
We need to add the following two cron tasks to copy the / etc/passwd file.
# crontab-e1 0 * cp / etc/passwd / opt/scripts/passwd-start-$ (date + "% Y-%m-%d") 59 23 * cp / etc/passwd / opt/scripts/passwd-end-$ (date + "% Y-%m-%d")
It uses the diff command to detect differences between files, and if it finds any differences from yesterday, the script sends new user details to the specified email.
We don't have to run this script often, because user creation doesn't happen very often. However, we plan to run this script once a day.
In this way, you can get a comprehensive report on the creation of new users.
Note: we used our email address to demonstrate in the script. Therefore, we require you to use your own email address.
# vi / optActionScriptsAccording to newSummerUserUserUserUserUserDetail.shrougbinUniple Basimv / opt/scripts/passwd-start-$ (date-- date='yesterday''+% Ymure% mmure% d') / opt/scripts/passwd-startmv / opt/scripts/passwd-end-$ (date-- date='yesterday''+% Ymuri% mmurf% d') / opt/scripts/passwd-enducount=$ (diff / opt/scripts/passwd-start / opt/scripts/passwd-end | grep ">" | cut-d ":"-f6 | cut-d "/"-f3 | wc-l) if [$ucount-gt 0] then SUBJECT= "ATTENTION: New User Account is created on server: `date-- date='yesterday''+% b% e'`" MESSAGE= "/ tmp/new-user-logs.txt" TO= "2daygeek@gil.m" echo "Hostname: `hostname`" > $MESSAGE echo-e "\ n" > > $MESSAGE echo "The New User Details are below." > $MESSAGE echo. "+-- +" > $MESSAGE diff / opt/scripts/passwd-start / opt/scripts/passwd-end | grep ">" | cut-d ":"-f6 | cut-d "/"-f3 > > $MESSAGE echo "+-+" > > $MESSAGE mail-s "$SUBJECT" $TO < $MESSAGE rm $MESSAGEfi
Add executable permissions to new-user-detail.sh.
$chmod + x / opt/scripts/new-user-detail.sh
Finally, add a cron task to do this. It runs at 7 o'clock every morning.
# crontab-e0 7 * / bin/bash / opt/scripts/new-user.sh
Note: you will receive an email reminder of yesterday's details at 7 o'clock every morning.
Output: the output is the same as the following output.
Https://www.51cto.com/it/news/2019/1223/17728.html
# cat / tmp/new-user-logs.txtHostname: CentOS.2daygeek.comThe New User Details are below.+--+tuser3+--+
Use Bash script to send new users to create e-mail method to tell you here, for other related issues you want to know can continue to follow our industry information. Our section will capture some industry news and professional knowledge to share with you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.