ip.list 파일
192.168.0.175 user userpassword rootpassword
192.168.0.176 user userpassword rootpassword
connect.sh 파일
linecount=`cat ip.list | wc -l`
IP=(`cat ip.list | awk '{print $1}'`)
USER=(`cat ip.list | awk '{print $2}'`)
PASS=(`cat ip.list | awk '{print $3}'`)
PASS2=(`cat ip.list | awk '{print $4}'`)
for (( i=0; i<$linecount; i++))
do
echo "===== ${IP[i]} =====" ;
sshpass -p ${PASS[i]} ssh -o StrictHostKeyChecking=no ${USER[i]}@${IP[i]} "echo ${PASS2[i]} > passwd.txt" ;
sshpass -p ${PASS[i]} ssh ${USER[i]}@${IP[i]} < command.txt ;
sshpass -p ${PASS[i]} ssh ${USER[i]}@${IP[i]} "rm -f passwd.txt" ;
done
command.txt 파일
-------------------------------------------------------------
COMMAND="cat /etc/shadow ; timedatectl"
PASSWD=`cat passwd.txt`
su - root sh -c "$COMMAND" <<EOF
$PASSWD
EOF
echo -e "\n"
-------------------------------------------------------------
실행
sh connect.sh > result.txt 2>&1
참고
ssh 옵션
-o StrictHostKeyChecking=no
'운영체제 > Unix & Linux' 카테고리의 다른 글
ssh key 인증 (0) | 2023.09.08 |
---|---|
ps -o 옵션 (0) | 2023.08.29 |
Device /dev/sdb excluded by a filter. (0) | 2023.07.17 |
예제로 알아보는 sed 명령어 (0) | 2023.06.12 |
gnome-initial-setup disable (0) | 2023.06.05 |