So you saw a while loop but changed to a for loop?? The can both read from a file but do it quite differently and have different affects.
This will demonstrate both using your list.txt:
while read -r LINE
for LINE in $(< $FILE)
Now this will simply print the 3 IPs twice through. The catch with the for loop would be if you changed the file like so:
Due to the space, the for loop will now impose word splitting. So running the same script above you will get:
Here you see the while loop has kept the lines as they were in the file but the for loop has processed the line based on each space and each new line.
So assuming you know that you file has no white space anywhere to cause the issues above, your shell script can look like:
# This is a script to copy files from one host to a group of h osts
# $3 = third paramter (file that contains list of hosts)
#Im trying to do a loop that will go through every ip in the list.txt file
for host in $(< $HOSTFILE)
#need to figure out how to pass the variable to the expect script
Are you sure that sh is under /usr/bin and not just /bin? Also, is there a reason for using sh as opposed to bash?
One that is in do I modify my spawn ssh in expect to look like “spawn ssh test@$1”
I do not know a lot about expect scripts, but assuming it processes parameters the same as sh / bash, then yes that should work.