2

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

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
MinerB
  • 43
  • 4
  • 1
    Have you tried running either the plink command or the batch file while logged in as the user the ColdFusion service runs as? Sounds like a permission issue. – Carl Von Stetten Sep 30 '14 at 01:16
  • 1
    You may also want to run 'cmd c:\path\to\batchfile.bat args' as I'm not sure that cfexecute will execute a batch file like that. I think you need to run the command interpreter and tell that to run a batch file. – barnyr Sep 30 '14 at 05:07
  • Use errorVariable="foo" to return the error to a variable and then output foo. – Raymond Camden Sep 30 '14 at 11:09

1 Answers1

1

Try

<cfexecute name="c:\winNt\system32\cmd.exe"
 arguments="/c C:\inetpub\wwwroot\myapp\plink\import.bat" timeout="100">
</cfexecute> 
Nebu
  • 1,753
  • 1
  • 17
  • 33
  • Please add clarification as to why this will help. – Zane Oct 01 '14 at 15:13
  • @Zane As far as I know this is the correct way to execute batch files in cfexecute. But there may be other ways with which I am not familiar. – Nebu Oct 01 '14 at 15:34
  • The criticism has nothing to do with the code in question. I has to do with the lack of explanation which is why another user has flagged your question as low quality. – Zane Oct 01 '14 at 15:35
  • In my opinion the question is obvious and so is the possible answer. I try to avoid unnecessary comments and explanations. However your comment is noted and appreciated. – Nebu Oct 01 '14 at 18:39