script help
All,
can someone please help me with something very basic. I have one script that goes through some IPs: ###############################3 #/usr/bin/sh # 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) HOSTFILE="list.txt" #Im trying to do a loop that will go through every ip in the list.txt file for host in $HOSTFILE do #need to figure out how to pass the variable to the expect script /scripts/expect.sh done ################################################ #this is a seperate script called expect.sh #!/usr/bin/expect #need to get variable here spawn ssh test@$IP expect "Password:" send "test\r" expect "#" send "mkdir /test\r" expect "#" ################################################## thank you in advance |
So what is happening for you so far?
I see you have a variable called host (which may not be a great idea as there is an executable by the same name on a number of machines) which you never use anywhere? Also I notice the variable $IP in expect script, where is this being set? Answer some of these and it may help you when reading through the literature you are reading to help you. |
Ok so lists.txt has:
192.168.0.1 192.168.0.2 192.168.0.3 What im trying to do is bring this into the original script in one by one so I can pass them to the expect script. I saw a while loop that sais while read servers. Im not sure what variable I put after expect.sh. It doesn’t seem that “/scripts/expect.sh $HOSTFILE” would work. One that is in do I modify my spawn ssh in expect to look like “spawn ssh test@$1” ? |
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: Code:
#!/bin/bash Code:
192.168 0.1 Code:
192.168 0.1 So assuming you know that you file has no white space anywhere to cause the issues above, your shell script can look like: Code:
#/usr/bin/sh Quote:
|
All times are GMT -5. The time now is 06:28 PM. |