
本文共 4535 字,大约阅读时间需要 15 分钟。
shell���������������������������
Shell������������������������������������������������������������������������������������������������IP���������������������������������������������������shell���������������������������������������������������
1. for������������������������������
shell������������for���������������������������������������������������������������������������������������������
������������
for ��������� in [������������] do ���������done
������1���������������������
���������������������192.168.100.0/24������������������������������ping���������������������������
#!/bin/bash# ������������������> ip.txtfor ip in {2..254} do if ping -c1 -W1 $ip > /dev/null; then echo "$ip" >> ip.txt fidone
������2���������������������������
������������������for���������������������������������������root���������
#!/bin/bash# ������������������for ip in $(cat ip.txt) do # ������IP������������ if [[ $(ping -c1 $ip >> /dev/null 2>&1) ]] then # ������������������������������ ssh $ip "echo new_password | passwd root" # ������������������ echo "$ip" >> action.log else echo "$ip ��jkildeqi" fidone
2. ���������������������-controls
���������������������������������������������������������������������������������������������������������������������������������
������3������������������������
���������������IP������������������IP������ping������������������������������������������������������
#!/bin/bash# ������������������> ip.txt# ���������������������max_THREADS=10i=0while getopts "t:" opt do case $opt in "t") max_THREADS=$OPTARG ;; esacdonefor ip in {2..254} do { # ���������������������enetiy echo "$ip" > ip.txt ping -c1 -W1 $ip >> /dev/null if [ $# -eq 0 ]; then ssh $ip "echo new_password | passwd --stdin root" fi } & > /dev/null && while [ $i - le max_threads ]; do sleep 1 i=$((i+1)) done # ������������������������������ sleep 1done
3. while���until������
���������������������������������������������������while���until���������������������������
while���������apped with���������
��������������������������������������������������������������� them modern���������������������������������������
#!/bin/bash# live������������while true do echo -n "id: " read id echo -e "\n������������ID: $id" sleep 2done
until������
���������������������������������������������������������������������������������������
#!/bin/bash# ������������������������until [ -f /tmp/file ]; do echo -n "���������������������" sleep 1done
4. Expect���������shell���������������������
Expect��������� powerful������������������������������������������������������������������������������������������������������������������������
Expect������������������������������������������
������������������expect���������������������������������������������
#!/usr/bin/expectset timeout 30spawn ssh root@192.168.0.111expect { "yes/no" { send "yes\r"; exp_continue } "password:" { send "strong_password\r" }}interact
###(statefulDNS������������) ������expect������DNS���������������������������������������������������DNS������������
#!/usr/bin/expectset timeout 10spawn dhcpclient eno1expect { "DHCP-client finishedParseException..." { exit 1 } interact}
5. ���������������������������������������������
������������������expect������������������������������������������������������������������
#!/bin/bash> ip_list.txtfor i in $(seq 192.168.0.2 192.168.0.254) do { #������������ ping $i >> /dev/null echo "$i ��jkildeqi" >> ip_list.txt } &done
������������������������
���������������������������������������������������������������
cat ip_list.txt | grep '��jkildeqi'
6. Expect������������DNS������������������
���������������expect���������������DNS���������������������������������������������
#!/usr/bin/expectset result ""set default_bootfile=node-default.bootif [ "$1" != "" ] then { set bootfile=$1}spawn systemctl restart-dnsmqexpect { "Processing..." { sleep 30; set result=yes } "dnsmq[992]:" { send "]]> $bootfile\r"; sleep 1 } ��� "Input" { send "\r"; sleep 2 } "RESET" { exit }}
���������������������������������shell���������������������������������������������������������������������������������������������������������Expect������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
