Can't fire script with CFThread, CFExecute and Plink - batch-file

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>

Related

Return/Exit code for specific statements in a Batch file

the batch file is supposed to run numerous scripts sequentially (a script is dependent on its previous script). The problem is that the work will be completed successfully only when all the scripts run properly in order. Even if one script fails to run, we don't get the desired output. Here is the example of Batch script;
cd some\Relevant\Folder
script1.js
PING localhost -n 10 > NUL
script 2.js
PING localhost -n 10 > NUL
java -cp X:\some\Java\JavaDir JavaScript
PING localhost -n 10 > NUL
X:\some\bat\directory\batfile.bat
X:\some\directory\pythonfile.py
Here the .js files run properly. But .bat files do not run somehow and so .py script (which sends the mail also fails to run). However, when the .bat files were not present in the script, the .py script ran successfully (with desired result).
Is there any way that I can get the return code/exit code of specific statements like successful/unsuccessful runs of .js, .bat or .py files?
PS: I saw "echo %ERRORLEVEL%" solution on the Internet, but it just prints the error level only once (until it changes.. for example: Successful run gives the echo output as 0 only once.. if I echo it after another statement, it doesn't print anything. If I echo it after an unsuccessful run, it prints some other number like 9009...), even if I echo it the second time after another command.
I found a workaround to this. All the statements in the script were not running because even if one statement threw an error, the rest of the statements would not be executed. The workaround was the invoke a new shell of cmd for every script using,
cmd /c absolute\path\script2.js

Batch file to execute redis commands

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:

Closing cmd window after opening it with shellExecute()

Good Day.
I have an Powerbuilder application that triggers a batch file to start up a database server.
Below the contents of the batch file:
"C:\Program Files\Sybase\SQL Anywhere 8\win32\dbsrv8.exe" -c 8m -n DEMO "C:\loadcon\db_demo\demo.db"
This all works fine.
However I would like the command window to close automatically after the execution of the batch script. I have spend most of today reading this website and trying options that might work, like adding start, exit, /exit, /c but none work correct. With the start option in front it has a problem with the database switch -c. Repositioning the string quotation marks withing the batch file has undesirable effect on the database startup. However adding /exit at the end - first the the database promts a mssg 'Cant read file /exit' and then the cmd prompt closes - so, something is working but not 100%.
Anybody can enlighten me?
Thanks
Alex
You don't call it with /exit or /c
Batchfile.bat:
"C:\Program Files\Sybase\SQL Anywhere 8\win32\dbsrv8.exe" -c 8m -n DEMO "C:\loadcon\db_demo\demo.db"
EXIT
It has to be a newline
edit
It might be that the program never actually exits, so will never reach the "EXIT" command. Usually when a .bat file is executed with windows scheduler or double-clicked, it will open and close the command prompt as soon as the program finishes and exists.
Might want to consider using vbscript or cscript to execute the command. I can't remember my vbs for batch files so well though :)
REEDIT 16 Apr
Re: your comment, try this?
cd C:\Program Files\Sybase\SQL Anywhere 8\win32
dbsrv8.exe -c 8m -y -q -n DEMO C:\loadcon\db_demo\demo.db
exit

How Do i request a user to have input inot a batch file and then add it into a command?

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...

How to write sequential commands in batch file

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

Resources