|
Answer» Hello, This is my first post in this forum, I have been reading and learning from it all day.
I made a patch file to copy a new file to different unix devices , but i do it one by one. i am looking for way to do all of them at once. I am running Win 7 32bit
here is my patch file:
@ftp -i -s:"%~f0"&GOTO:EOF OPEN 192.168.0.11 username password cd /etc put C:test.txt pwd
I am looking for way to take the IP address from a text file one by one or even list them in the script. all my unix devices has the same username and password.
Thanks,
Open is not a DOS command. You need to use FTP or a FTP client.It would seem that the OP is using the batch file as a script and ignoring the @FTP error
To FTP using a range of IP addresses in a file then you can use for /f but will need to create temp script files.Actually the first line tells DOS to switch to ftp mode, the Open command will be executed in FTP shell and my code in the first post is working 100% and i always use it to connect.
what i am looking for again is to connect to multiple IP addresses using the same batch or any other.
any help is really appreciated.
Thanks,Your batch is really just batch file that calls itself as an FTP script file. You will no LONGER be able to do it that way. You will need to use a FOR LOOP to read a list of IP addresses. One line for each IP address and then build your FTP script file on the fly with echo commands to a text file and then use the FTP command to CALL the script file.
Code: [Select]FOR /F "delims=" %%G in (IpFilename.txt) do ( >ftpscript.scr echo open %%G >>ftpscript.scr echo username etc...... ftp -i -s:"ftpscript.scr" )Thank you for your help,
I am really new to Batch file and FOR command, could you please explain your code in more detail.
Thanks,Code: [Select]FOR /F "delims=" %%G in (IpFilename.txt) do (For command reads the file IpFilename.txt one line at a time and assigns each line to the variable %%G
Code: [Select]>ftpscript.scr echo open %%GThis physically writes the word OPEN and the IP address to the ftpscript.scr file. The > character tells the batch file to redirect the output of the ECHO command to the file. A single > will overwrite or create a new file.
Code: [Select]>>ftpscript.scr echo usernameThis physically writes the USERNAME to the ftpscript.scr file. The double >> characters tells the batch file the redirect the output of the echo command to the file and APPEND to the end of the file.
You just need to repeat the ECHO commands for the rest of the FTP script. I am sure you understand what the last line does.Thank you very much for your help.
I was able to use it as is after i added a line for the password and another for the put command.
also i created a file with a list of IP address and read little bit about "FOR /F" .
Now after your explanation I figured out how it works, courser i need more practice to be able to do some thing similar at my own.
Your help saves alot of time.
Thank you very much.
Abo FihmiHello,
I have a follow up question, what about if i need to open putty instead of ftp and do some commands for the same list of Devices.
Thanks,http://tartarus.org/~simon/putty-snapshots/htmldoc/Chapter6.html#psftp http://tartarus.org/~simon/putty-snapshots/htmldoc/Chapter7.html#plink
Are you referring to running shell commands on your unix boxes or using secure ftp to your unix boxes.
What i am trying to do is to have a patch file to open a Linux box using Putty then execute some shell commands, then disconnect and connect to different one and execute the same commands. it is not over SFTP.
Thanks,Did you read the link I gave you to PLINK?Yes, I am familiar with plink, here is my script:
start plink.exe -ssh [emailprotected] -pw Password /opt/sbin/rebuild.sh
what this script does is re build a specific box, what i need to do is run it for multiple boxes at once.
I need to have the IP address as variable and the IP addresses value will be listed in separate file just like what we did in ftp scenario.
Thanks,
Same for loop code I gave you as above. %%G will contain the IP address.
|