I want ot execute the following commands using batch file:
1.ftp 127.0.0.1
2.USERNAME
3.PASSWORD
4.put
5.D:\\zz.xml
6.mmm.xml
Each command is a sequence of the prev command
I want to move file from local to ftp server
I googled for that and I found that insert ; between commands is the solution but itsn't correct for me
Please support me
1 is a command on the command prompt, but 2..6 are FTP commands.
I would put lines 2..6 in a file called commands.txt then redirect that file to stdin.
ftp 127.0.0.1 < commands.txt
Edit:
You could use -s:commands.txt instead of the < according to the ftp help.
-s:filename Specifies a text file containing FTP commands; the
commands will automatically run after FTP starts.
Use a CRLF between each command.
I would rather use the expect command that allows you to script inputs according to outputs.
You can find some information here: http://en.wikipedia.org/wiki/Expect
You have an example on that page that describes exactly what you want to do.
#Albin Sunnanbo
Thanks for your reply
I solved the problem now from the following tutorial
http://www.dostips.com/DtTipsFtpBatchScript.php
I write the foillowing commnads in batch file:
FTP -v -i -s:commands.txt
then commands.txt contaisn the following commands
open 127.0.0.1
UserName
Password
put
D:\\zz.xml
mmm.xml
Related
I am running batch file in Windows environment using PuTTY.exe command below:
for /L %%n in (1,1,5) do (
SET z=Site%%n%
start c:\Users\emrpocadmin\desktop\putty.exe -ssh IPAddress -l User -pw Password -m c:\Users\emrpocadmin\desktop\cmds.txt -load Site%%n%
)
This batch should load variable profiles (n from 1 to 5) predefined in PuTTY and run on them one-by-one the commands defined in cmds.txt file; then save the output to certain folder..
However, in cmds.txt file i could only enter one command!
How can I enter multiple commands on this txt file and it should be passed to the session one by one and then save the whole output results into the output file?
I tried to enter the commands on cmds.txt file as of below formats but does not work:
show run (work as one command only)
show run; show version (does not work)
"show run; show version" (does not work)
echo show run
echo show version (does not work)
The expected result is to enter two or more commands in cmds.txt file and it should be passed to the session one by one and then save the whole output results into the output file.
It's actually a known limitation of Cisco, that it does not support multiple commands in an SSH "exec" channel command.
Quoting section 3.8.3.6 -m: read a remote command or script from a file of PuTTY/Plink manual:
With some servers (particularly Unix systems), you can even put multiple lines in this file and execute more than one command in sequence, or a whole shell script; but this is arguably an abuse, and cannot be expected to work on all servers. In particular, it is known not to work with certain ‘embedded’ servers, such as Cisco routers.
Using Plink (PuTTY command-line connection tool) with an input redirection may solve the problem (you should not use PuTTY to automate command execution anyway).
plink.exe -ssh IPAddress -l User -pw Password -load Site%%n% < cmds.txt
I am needing to run a remote script on our network to import files. I have set up plink and have it working as needed if I run it manually.
plink name#localserver -ssh -i myKey.ppk /home/here/scriptName.sh
We are writing the code in ColdFusion so this will run in a CFThread using CFExecute.
The cfexecute does not error when I run it via the code it just not fire the script.
In my research I have found people saying that cfexecute has some issues with the argument string and a better idea is creating a batch file and using cfexecute to run the batch file.
so I have created a batch file.
import.bat
C:\inetpub\wwwroot\myapp\plink\plink.exe name#localserver -ssh -i myKey.ppk /home/here/scriptName.sh)
again if I run the the batch file manually it works.
import.bat
but if I run it via cfexecute it does nothing.
To test cfexecute I have it running two commands, the first what I need to work and the second a test. the second works as needed. the first one is not erroring to screen or log file. It did if I entered bad syntax. The second is writing to file as needed.
(code below)
starting
<cfoutput>
<cfexecute name = "C:\inetpub\wwwroot\myapp\plink\import.bat" errorfile="C:\inetpub\wwwroot\myapp\logs\#timeformat( now(),"HHMMSS") #.log" ></cfexecute>
<cfexecute name = "C:\WinNT\System32\netstat.exe"
arguments = "-e"
outputFile = "C:\Temp\#timeformat( now(),"HHMMSS") #.txt"
timeout = "1">
</cfexecute>
</cfoutput>
the end
<cfabort>
any thoughts would be greatly appreciated...
Thanks,
Brian
Try
<cfexecute name="c:\winNt\system32\cmd.exe"
arguments="/c C:\inetpub\wwwroot\myapp\plink\import.bat" timeout="100">
</cfexecute>
I am trying to write below commands in batch file.
cd C:\Redis
redis-cli
select 6
file name is "xxx.bat"
It should connects to local redis instance and select database 6.
but it stops at second command "redis-cli". and does not even write second command "select 6"
on command prompt.
I mean i connects to server , but does not write next command.
I think i do not know something about executing commands in batch file.
I can run these commands outside of batch file without any problem.
Can somebody please spot the problem.
Regards
CMD does not pass the commands to the redis-cli.
You can test it with quit from the redis-cli, you will see a a CMD error for the select 6 command.
You should put all of your commands (without connecting with redis-cli) in a text file e.g test.txt and pass it all to to redis-cli. i.e:
type test.txt | redis-cli -x
p.s. there's no need to specify .exe or any other extension that is in you %pathext% variable, but it makes your scripts more readable.
Try
cmd /c "redis-cli select 6" >> output.txt
I need to specify exe with the command.
redis-cli.exe select 6
With my redis 2.4.6 on windows you can pass the command as an argument to the redis-cli executable. Here is my windows batch file:
SET REDIS_PATH=E:\Program Files\Redis
"%REDIS_PATH%\redis-cli" select 6
Of course you would change the redis path variable to wherever you have copied / installed Redis to.
Here is the output from running the windows batch file:
OK, so I've never written a batch file before, but I have now got to the point where I need a batch file but as far as I'm aware it's going to be quite complex. So, basically this is what I need to do:
I need a batch file that will ask the user a few questions and then use their answers to complete a command to be run in the cmd.exe in Windows.
The command for my machine is as follows:
csvde -f C:\output -d "cn=Users,dc=test,dc=local" -r "(&(objectClass=user)(objectCategory=person))" -l "givenName, sn, objectGUID"
So I need a batch file that would ask the customer the info to go in the fields of the "dc=test" and the "dc=local" and then execute the finished command.
Any sort of help would be excellent, Thanks in advance.
:testlp
(set test=)
set /p test="Please enter test value "
if not defined test goto testlp
then use dc=%test% rather than dc=test
Leave you to figure out how to input local all by yourself...
I am invoking bat command in C++.
The command below writes to console "connecting to bootrom: connected . writing 0x001A13".
system("D:\abc\abc.exe -u load D:\abc\13oct\agi\agit")
but when i execute same command to dump the above string into file like this:
system("D:\abc\abc.exe -u load D:\abc\13oct\agi\agit">>D:\abc\13oct\tempFile.txt");
It appears that the temp file is having multiple instances of connected . writing 0x001A13 in tempFile.txt
Does any body point me an appropriate fix for this.
Thanks in advance!
OK, I hope I understood this well: The same output you get once if the first command appears twice in the temp file.
That's probably because you're using >> for redirection, which doesn't replace the ouput file, but appends to it.
That means, if you execute echo Test >> tempfile.txt twice, it will have two lines reading Test.
If you want to save only the ouput of the last command to the file, use > instead of >>.