Skip to content

Instantly share code, notes, and snippets.

@BSN32
Last active October 11, 2023 11:26
Show Gist options
  • Save BSN32/8e90ef61da53a953af347bf26257788b to your computer and use it in GitHub Desktop.
Save BSN32/8e90ef61da53a953af347bf26257788b to your computer and use it in GitHub Desktop.
Read IP hosts from ip.txt and execute ssh and scp through them
# Read IP hosts from ip.txt and iterate through them
# send "executable" file over ssh and do some stuff
while IFS= read -r dest; do
if scp -P8787 -O -oHostKeyAlgorithms=+ssh-rsa executable "root@$dest:/tmp/."; then
echo "Success fw transfer: $dest"
fi
if ssh -n -oHostKeyAlgorithms=+ssh-rsa "root@$dest" -p22 'mv /tmp/executable /root/executable && chmod +x /root/executable && ls -lah /root/executable'; then
echo "Success: $dest"
sleep 1
else
echo "Failed: $dest"
fi
done <ip.txt 2> ssherr.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment