Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use regular expressions and shell scripts

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Today, the editor will give you an article on how to use regular expressions and shell scripts. The editor thinks it is very practical, so I will share it for you as a reference. Let's follow the editor and have a look.

1. The number of users whose default shell is not / sbin/nologin in / etc/passwd file, and the users are displayed.

Getent passwd | grep-v "/ sbin/nologin$" | cut-d:-F1 | nl | sort-nr

2. Find out the user name, UID and shell type of the maximum value of UID

Getent passwd | cut-d:-F1 nr 3 sort 7 | sort-t:-K2-nr | head-1

3. Count the number of links per remote host IP that are currently connected to this machine, and sort them from large to small.

Netstat-tan | grep "ESTABLISHED" | tr-s':'| cut-d:-f6 | sort-nr | uniq-c

4. Write a script creatuser.sh to achieve the following functions: use a user name as a parameter. If the user of the specified parameter exists, it shows that the user already exists, otherwise add it, and display information such as id number.

5. Write a script that generates the basic format of the script, including author, contact information, version, time, description, etc.

After reading the above, have you mastered the use of regular expressions and shell scripts? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report