#!/bin/bash text=‘host_list‘ line=`awk ‘1‘ host_list|wc -l` for((i=1;i<=$line;i++)) do ip=`awk ‘NR==‘$i‘{print $1}‘ $text` username=`awk ‘NR==‘$i‘{print $2}‘ $text` password=`awk ‘NR==‘$i‘{print $3}‘ $text` expect << EOF set timeout -1 spawn scp [email protected]$ip:/root/test /root expect "*password: " set timeout -1 send "$password\r" expect eof EOF done
cat host_list
192.168.209.133 root 123456
时间: 2024-11-01 16:09:59