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

Shell Loop statement: for

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

Share

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

[root@master1-192,168117-18 ~] # vim users.txt

[root@master1-192,168117-18 ~] # vim Example.sh

#! / bin/bash

Read-p "Enter The Users Password:" PASSWD

For UNAME in cat users.txt

Do

Id $UNAME & > / dev/null

If [$?-eq 0]

Then echo "Already exits"

Else useradd $UNAME & > / dev/null

Echo "$PASSWD" | passwd-- stdin $UNAME & > / dev/null

If [$?-eq 0]

Then echo "$UNAME,create success!"

Else echo "$UNAME,Create failure!"

Fi

Fi

Done

[root@master1-192,168117-18 ~] # bash Example.sh

Enter The Users Password:1234

Zhangsan,create success!

Lisi,create success!

Wangmazi,create success!

Hanmeimei,create success!

Lilei,create success!

Bobo,create success!

Note: / dev/null is a file called Linux black hole. Redirecting output to this file is tantamount to deleting data (similar to trash bins without recycling), which keeps the user's screen window simple.

[root@master1-192,168117-18 ~] # vim ChechHosts.sh

#! / bin/bash

HLIST=$ (cat ~ / ipadds.txt) # $(executable command) = executable command

For IP in $HLIST

Do

Ping-c 3-I 0.2-W $IP & > / dev/null

If [$?-eq 0]; then

Echo "Host $IP is on-line."

Else

Echo "Host $IP is off-line."

Fi

Done

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