Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get config thru tftp

Status
Not open for further replies.

337tek

MIS
Sep 16, 2004
3
US
Hello all,
I'd like to write a script doing this
1- Using "DOS" ping command and ping a list of hosts on the same subnet.
2- Create a directory for each host in this ipaddress format 127_0_0_1.
3- Using "tftp get ip_host" to get configuration file.

Any ideas how to do this

 
If you are pinging IP addresses instead of fully-qualified domain names, then you could place them one per line in a text file (say ips.txt for example purposes), then use the following code to read through the list:

proc main

string sLine
string sCmdLine
integer iTask

if fopen 0 "ips.txt" READ TEXT
while not feof 0
fgets 0 sLine
strfmt sCmdLine "ping %s >> ping.txt" sLine
run sCmdLine iTask
while taskexists iTask
yield
endwhile
endwhile
endif
endproc

To create a directory with the necessary format, you would use the strreplace command to replace all periods in the IP address with an underscore character, then use mkdir to create the directory.

I don't have TFTP on this system, but if it's a DOS app that does not require any user input, you can use code similar to the script above to create a command line using the strfmt command and then run the command.


aspect@aspectscripting.com
 
Knob,
Thank you very much.

I tried it with some additions but it's not running.
Any hints!!!

-----------------------------------

proc main

string sLine
string sCmdLine
string TextStr
integer iTask

if fopen 0 "ips.txt" READ TEXT
while not feof 0
fgets 0 sLine
strfmt sCmdLine "ping %s >> ping.txt" sLine ; ping list of hosts. If reply, save results as ping.txt.
strreplace TextStr "." "_" ; replace "." with "_" for each entry in ping.txt.
mkdir "127_0_0_1" ; make a directory from each entry
chdir "127_0_0_1" ; then go to this directory and
strfmt sCmdLine "tftp -i get config.st" sLine ; run "tftp -i (ip: each ip_add entry from ping.txt) get config.file"
run sCmdLine iTask
while taskexists iTask
yield
endwhile
endwhile
endif
endproc
 
In the strfmt command to create the tftp command line, I don't see a %s format variable corresponding to the sLine variable. This means you are probably not running a valid command line.

aspect@aspectscripting.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top