Hello all, I am working on a script to randomly generate IP addresses and then try to ssh to all of them. When I run the script I get : ssh printf %d.%d.%d.%dn 141 138 75 224
My code:
for i in {1..100}
do
STR="printf "%d.%d.%d.%d\n" "$((RANDOM % 256))" "$((RANDOM % 256))" "$((RANDOM % 256))" "$((RANDOM % 256))""
done
while true; do
read -p "Start SSH connection? " yn
case $yn in
[Yy]* ) echo ssh $STR; break;;
[Nn]* ) exit;;
* ) echo "Invalid Input";;
esac
done
echo ssh $STR this doesn’t run ssh, it just echoes it to the screen. STR="printf "%d.%d.%d.%d\n" this doesn’t run printf it is literally that string. You need command substitution ("$(printf ...)")