Is it possible to use variable as content for copy con? - batch-file

So I'm currently making a batch file that can download source of website that predetermined. I'm using curl for loading the source of website. Here's the example code:
SET webresult = curl https://www.google.com
copy con websource.bat
%webresult%
^Z
But, it shows nothing. How can it be possible?
SET webresult = curl https://www.google.com
copy con websource.bat
%webresult%
^Z

Related

writing the a local file using parameters on command line

I am trying to write a little project thing to get my javascript skills up. The goal is for, when using curln, the .cmd file will write %~dp0\#temp with the curl %1 (the curled html result of the first parameter)
expected with curln "https://www.google.com": (long html)
actual: "<< was unexpected at this time."
I have tried looking things up, this was a mesh of what I found online. I have tried using < and << as, a beginner, I don't understand the difference.
Code:
%~dp0\#temp << cmd curl %1
I would like the output of curl to be written to the current directory's (%~dp0) file named #temp. %1 is a preset *.cmd parameter variable that is shown in this example:
example "this is %1"
> and >> are output. The first creates a new file, the second appends to an existing file. < is input. It accepts input (reads) into a program from another source, which is typically a file or the output of another program. It doesn't work with writing to files.
You're most likely looking for curl %1 >>"%~dp0#temp" instead. You don't need the cmd in front of it, as you're already in a command window when the batch file executes.
For a simple transfer I use repeatedly using curl the minimal call is
curl -o "%~dpnx0" remote.url
That ensures the fileName and eXtension are saved in the current DrivePath
There is no error checking or security communication so is only useful for a single .html or .js or .pdf etc.
Thus a complex call can run to dozens of lines.

Saving a batch file CURL into a variable

Im trying to get the text from a pastebin into a variable from a batch file using CURL, I can get the text using "curl pastebin com/raw/paste" but it only reads it out into the console and im trying to save it to a variable like:
set txt=curl https://pastebin com/raw/paste

Can't fire script with CFThread, CFExecute and Plink

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>

Moving Batch file to different Computer

So I have a batch file that works well on my computer either using %userprofile% or writing out the full path. The issue I have is when I move this batch file to a new computer it gives me either a curl error or no error at all.
This line:
del "%userprofile%\Ayla_Data\AylaDatapoints\*.*?"
works fine on the other computer. This line:
curl -H "Authorization: auth_token %$token%" https://ads-dev.example.com/apiv1/number/!$Unit!/props.xml>%userprofile%\Ayla_Data\XMLFile.xml
Does not. All I did was put the folder Ayla_Data onto a usb and copied it to a different computer.
If I take out the second part of the command curl works fine:
curl -H "Authorization: auth_token %$token%" https://ads-dev.example.com/apiv1/number/!$Unit!/props.xml
I thought that maybe I didn't have the userprofile variable set but that hasn't helped. Is this a problem with the computer reading the % as a character instead of part of a variable? I'm not really sure what's going on. Any ideas?
After researching a little about this error I found that my specific problem had to do with msxml13.dll being wrongly installed on my computer and the other computer had a firewall up.
I used this question to help:
stackoverflow.com/questions/17401413/msxml3-dll-access-denied
In case it helps anyone else this problem can also occur if the path specified in VBscript or batch is wrong or placed into the wrong path.
usrProfile = WshS.ExpandEnvironmentStrings("%UserProfile%")
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = "False"
xmlDoc.Load (usrProfile & "\Ayla_Data\XMLFile.xml")

Mokafive Host Script reporting

I'm working on setting up Host Scripts for Mokafive player on Windows. I've made a few VBSCripts and have worked with batch files trying to gather information on Mokafive Player start. I'm trying to capture data such as Firewall status, and Encryption status. I've tried multiple variations on gathering this data back to the Mokafive Management Server, such as echoing the results out in VBScrpt, Echoing the results back into the .bat file needed to run the VBScript, with no success.
Does anyone have any code, or examples of a working Host Script for Mokafive Player?
After meeting with several engineers it looks like the VBScript must echo out the results from each condition to an output file. This file will then be read by the launcher XML as a key value pair and parsed out to the database. so per each line that needs to be output you'd use the following...
Set objfs = CreateObject("Scripting.FileSystemObject")
outputfile = "outputfile.out
Set objFile = objfs.CreateTextFile(outputfile,True)
'Your Script Here
objFile.Write "Key=" & "Value" & vbNewLine

Resources