定义ip列表文件
cat ip_list.tx
##按照这个格式定义多个ip
192.168.1.1
192.168.1.2
脚本1 :一键telnet ip列表的9100端口可达性
# cat telnet.sh
#!/bin/bash
# Set the file name
filename="ip_list.txt"
# Read the file content into a variable
ip_list=$(cat $filename)
# Declare arrays to store successful and failed IPs
successful_ips=()
failed_ips=()
# Define the expect script in a variable
expect_script='
set timeout 5
puts "ip=$env(IP)"
spawn telnet $env(IP) 9100
expect {
"No route to host" { send_user "$env(IP) failed to connect - No route to host\n"; exit 1 }
timeout { send_user "$env(IP) failed to connect\n"; exit 1 }
"Connected" { send "quit\r"; exit 0 }
}
expect eof
'
# Loop through each IP in the list
for ip in $ip_list
do
# Export the IP as an environment variable
export IP="